sorting

How to sort an array of an array of objects by those objects attributes

If have an NSMutableArray foo of an NSMutableArray bar of objects. Each of the objects have a property that is a numerical value. In each NSMutableArray bar I want to sum this numerical property of each object. Then I want to sort the NSMutableArray foo by this sum. What's a good way to do this? ...

Using sortUsingSelector on an NSMutableArray

I have used sortUsingSelector to sort an NSMutableArray of custom objects. Now I'm trying to sort an NSMutableArray containing NSMutableArrays of custom objects. Can you use sortUsingSelector on an NSMutableArray, or does it only work for custom classes? ...

Swapping elements in an NSMutableArray

Are there any special methods to make swapping elements in an NSMutableArray easier or more direct? ...

jqGrid sort icon manipulation

How can you toggle the sort icons on/off? From another post I saw this seems to turn them off: $("#gbox_list .s-ico span").hide(). But this corresponding code did NOT seem to turn them on again: $("#gbox_list .s-ico span").show(). ?? And how can you manipulate them? Ie: How can you programatically set the second column to show the a...

Java - Mergesort counting

I have made a mergesort that is being juxtaposed with two already created selection and insertion sorts which both count the comparisons so that when executed the program illustrates which methods are faster. I can't figure out how to get a count implemented into my mergeset I really don't know if it's even working correctly or if I...

Checkbox gets reset in WPF Datagrid when sorting

I have a WPF application with DataGrid The DataGrid contains 4 columns with a checkbox template column on the first column the problem is when i check some of the checkbox on the items, the checkbox would got reset when i sort a certain column. For example i check the checkbox on the row 2 it gets unchecked when i sort the datagrid. be...

compare and sort different type of objects using java Collections

Hi, How to compare and sort different type of objects using java Collections .Below is the use case: For example DOG,MAN,TREE, COMPUTER,MACHINE - all these different objects has a common property say "int lifeTime". Now I want to order these obects based on the lifeTime property Thx ...

Grails Sorting Issue

Hi, I have a grails app developed. Herein, I have a page which accepts data and as per the data . goes to the list action, fires an sql, populates the data into reconciliationInstance object and displays it in list.gsp. In my list.gsp, I have, <g:sortableColumn property="access" title="${message(code: 'reconciliationInstance.acces...

Algorithm for sorting and pairing elements of 2 arrays

Hi, I am trying to configure an efficient algorithm (faster than O(n^2)) for sorting and pairing elements between 2 arrays. However this needs to work under the premise that neither array's elements can be compared to other elements in their own array. Edit: The elements of the arrays are "sizes" which correspond to particular objects. ...

Algorithm for sorting loosely comparable data?

Let's say I have an unsorted list of four objects: [B, C, A, D]. All four objects are of the same type, and: (A > B), (C > D), (A != C or D) (B != C or D) (C != A or B) (D != A or B). By "!=", I mean that they are neither less-than, equal-to, or greater-than the other objects. I need to "sort" the list such that A will alway...

How To Get the Median Of n odd elements using quicksort?

Can anyone explain how to improve the quicksort algorithm for finding the median of n odd numbers and what will be the worst case scenario for that algorithm? Please help. ...

Sort Sub Documents in MongoDB

Is there a way to sort sub docs in a mongo query? Example(Blog Collection): { "_id" : ObjectId("4c69d19532f73ad544000001"), "content" : "blah blah blah", "comments" : { {"author": "jim", "content":"comment content 1", "date" : "07-24-1995"}, {"author": "joe", "content":"comment content 2", "date" : "07-24-1996"} {"...

How can I sort by the average of a polymorphic child's attribute with ActiveRecord 2.3?

I have this schema: class Comment has_many :ratings, :as => :target end class Rating belongs_to :target, :polymorphic => true end I want to write a named scope that will sort comments by their average rating, without fetching the whole list of comments and then fetching all their ratings. I think I need to use :include and :grou...

Sorting an NSMutableArray containing matching "pairs" of values.

I'd prefer not to change the way anArray is designed because it is also used elsewhere as a dataSource for a UITableView. The odd number values are "user names", and the even number values are their matching "dates". (The "pairs" must remain together.) How would I sort "by user name"? How would I sort "by date"? Should I be using s...

How to sort an array of objects by their NSString property

I have an array of custom objects. One of the properties of these objects is an NSString. I want to sort by that property. Because it is an NSString and not an NSNumber sorting is a little more difficult. Is there some kind of class method to help in this case? How should it be done? ...

How should I fix this code?

I'm trying to sort an array of people objects. The class looks like this. Person ------- name phone I have an NSMutableArray filled with these objects. I want to sort this array by the name of each person object. This is the code I tried. NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES]; [pers...

C# custom list sorting...

Hello, I have a program that find all .csv reports file in a directory. This reports are stored in a List List<string> _items = new List<string>(); this reports are named like this: "month year.csv" (example: "Avgust 2010.csv") I would like to sort my reports by month. Months are in this order: januar, februar, marec, ap...

Fastest way to sort in Python

What is the fastest way to sort an array of whole integers bigger than 0 and less than 100000 in Python? But not using the built in functions like sort. Im looking at the possibility to combine 2 sport functions depending on input size. ...

Optimizing a cycle sort implementation

Cycle sort is an in-place sort based on the idea that the permutation you're sorting can be factored into cycles. If you rotate each cycle one position, the array will be sorted. This can easily be coded so that the number of writes to the array is the theoretical minimum needed for any in-place sort (which is nice for huge data sets on,...

Reversing dictionary by key doesn't work

I have a following dictionary : {2009: [12, 11, 10, 9], 2010: [1]} I'm trying to reverse-sort it, so that 2010 comes first. Here's the code : def dictSort(dict): items = dict.items() items.sort(reverse=True) dict = {} for item in items: dict[item[0]] = item[1] return dict But in return I get the same dicti...