sorting

sort perl numeric array

Hi, I have an array which looks like this: array[0]: 6 8 array[1]: 12 9 6 array[2]: 33 32 5 array[3]: 8 6 What I want to do is to sort this array that it looks like this: array[0]: 6 8 array[1]: 6 9 12 array[2]: 5 32 33 array[3]: 6 8 I know I can sort the array with @newarray = sort {$a cmp $b} @array;, but I need to sort the eleme...

Sorting a list pairs by frequency of the pair elements

I'm completely new to Python and while trying various random bits and pieces I've struck upon a problem that I believe I've "solved", but the code doesn't feel right - I strongly suspect there is going to be a better way to get the desired result. FYI - I'm using whatever the latest version of Python 3 is, on Windows. Problem definitio...

Which key class is suitable for secondary sort?

In Hadoop you can use the secondary-sort mechanism to sort the values before they are sent to the reducer. The way this is done in Hadoop is that you add the value to sort by to the key and then have some custom group and key compare methods that hook into the sorting system. So you'll need to have a key that consists essentially of bo...

Sorted result differs with inner and left joins in mysql

I just found this irregularitry in a query i made, why does the result differ when using inner and left joins? for one, the result is ordered both in the temporary hit table and in the final query? I made a little example to show the problem: # cleanup drop temporary table if exists ids; drop temporary table if exists arts; # create t...

How do I sort a multi-dimensional array by value?

I have an array as following and I want to order that array by the value of the key "attack". First keys of the arrays (15, 13, 18) are ID of some certain item from database, so I don't want these keys to be changed when the array is sorted. Any help would be greatly appreciated. This is the array: $data = array('15' => array('attack' ...

Format-List: sort properties by name

Is it possible to sort the output of the Format-List cmdlet by property name? Suppose that I have an object $x with two properties "A" and "B", and when I run Format-List with it I get (PS) > $x | Format-List B : value b A : value a I would like to have (PS) > $x | Format-List A : value a B : value b NOTE: I should have specified ...

PHP How do I shift subset of array values to do something like asort?

Hello. First off I am new to this site and it is a big help, so thanks in advance for the input. I am trying to shift a subset of array values after comparing them, like asort. Here is what I have: $array[name] = "name"; $array[date] = "date"; $array[item1] = 7; $array[item2] = 16; $array[item3] = 3; $array[item4] = 16; $array[item...

Regarding in-place merge in an array

I came across the following question. Given an array of n elements and an integer k where k < n. Elements {a0...ak} and {ak+1...an} are already sorted. Give an algorithm to sort in O(n) time and O(1) space. It does not seem to me like it can be done in O(n) time and O(1) space. The problem really seems to be asking how to do the merge ...

Merge function in Lua

Hey, I'm trying to implement the merge function from merge sort in Lua. I know the algorithm pretty well, but I'm new to Lua. I keep getting a "bad argument #1 to 'insert' (table expected, got nil)" I believe the error is pointing at my recursive call. I can't figure it out and I have a feeling it's something pretty trivial. I just n...

Java - Implementing sorting algorithms the 'right' way

I'm currently playing with implementing various sorting algorithms in Java, mostly for fun, but I'm struggling with how to do it 'right'. That is, I want the user to be able to call the sorting algorithm of choice on anything that is comparable - ints, longs, Strings, booleans (actually, are these comparable in Java?), their own classes;...

What's the most efficient way to query and sort a semicolon separated list of ids according to their associated strings from another table?

I have 2 tables in a mysql database : users and pets. In the users table there is a field that contains a semicolon separated list of the pets that a user has (pet_ids = 1;2;3;4;). These ids correspond to unique ids (keys) in the pets table which contain the pet name (1 = rex, 2 = goldie, 3 = squeak, 4 = bubble). I want to present a lis...

sort variables my own way in R

Dear all, I'd like to sort a categorical variable my own way. I have grouped my dataset into categories like "1-5","6-10","11-20" .... ">251" and so forth. If plot the variables or display them in a table the sequence of the legend respectively the sequence in the label is "messed up". This is not surprising since R does not know that...

Custom sorting for lucene

Hi I have document with fields like (title, content, datetime) I want to sort the results with the following formula 1) title boosts 2.5 2) content boost 1.5 3) IMPORTANT (boost those documents that is newer means datetime field is near today date) boost 3 how can I write a query considering the above criteria what should I do for #3...

Sorting a time value in a dataset

In my current solution, I am converting a DateTime value, "Time" in my database using CONVERT so it displays in a ##:##AM/PM format, and I realize that CONVERT just takes whatever datatype and turns it into a VarChar, or a String once its in C#. This is making my sort work incorrectly in my Gridview. I am sorting the columns in my DataSe...

sort a dictionary according to their values in python

Possible Duplicate: Sort by key of dictionary inside a dictionary in Python I have a dictionary: d={'abc.py':{'map':'someMap','distance':11}, 'x.jpg':{'map':'aMap','distance':2},....} Now what I need is: I need to sort d according to their distances? I tried sorted(d.items(),key=itemgetter(1,2), but it's not working. H...

Differences between Excel and SQL sorting

Programs used: SQL Server 2000, Excel 2003 We have a table in our database called Samples. Using the following query... SELECT [Sample], [Flag] FROM Samples ORDER BY [Sample] ... we get the following results: Sample Flag ---------- ---- 12-ABC-345 1 123-45-AB 0 679-ADC-12 1 When the user has the same da...

Need PHP to sort files ALPHA and NUMERIC

I have a bit of PHP code that grabs a list of files from a directory, and puts them into an array. I can sort the array alphabetically, and the file list comes out like this: (Ex A) CC 2010.pdf CCP 2010.PDF RS 1 2010.PDF RS 15 2010.PDF RS 2 2010.PDF I want PHP to sort alphabetically but also take into consideration sorting files wit...

Sorting Prices from XML

Hey Everyone, I am trying to sort the results by prices of an xml with info related to hotels. I want to display and sort the data by prices, given by a value called minCostStay, so ASC and DESC are must to do this. I am using foreach to display the data endlessly. What I need to do now is sort out these data by price asc and desc. I a...

Sorting an NSArray by an NSDictionary value

I'm trying to sort an array that would look something like this: (please ignore the fact these people are well past any living age! I just needed large numbers) NSDictionary *person1 = [NSDictionary dictionaryWithObjectsAndKeys:@"sam",@"name",@"28.00",@"age",nil]; NSDictionary *person2 = [NSDictionary dictionaryWithObjectsAndKeys:@"cody...

sorting people by their role on a company

Im trying to find a good way to sort people by their Role within a specific company. What makes it tricky, is that a person can have one or more roles in different companies. At the moment I have an array of 'Person' objects, and each of these objects has a NSSet of 'Roles' objects associated to it. Similar to this: Person -personId ...