sorting

What is the Average Big-Ο complexity of Gnome sort?

There is nothing about it in wikipedia. Anyone knows that? I only want to know the average Big-O Complexity of that algorithm. ...

How do I sort a ControlCollection by TabIndex or ChildIndex etc.?

Sorting a flat ControlCollection by TabIndex in a container is straightforward. It's complicated, however, when you have to sort a hierarchical container because the controls are renumbered. So you get something list this: Control 0 Control 1 Control 2 Control 3 Control 4 Control 5 How would I sort this? ...

jQuery.sortable. change the order by JS

How can I change the order of a list once applied by JS "jQuery.sortable". For example: <ul id="mylist"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> var x_sortable_list = $("mylist").sortable(); then, assuming this to work: x_sortable_list.changeOrder([ {item:1, newOrder:2 }, {item:2, newOrder:1 }, {it...

Interview question: C program to sort a binary array in O(n)

I've comeup with the following program to do it, but it does not seem to work and goes into infinite loop. Its working is similar to quicksort. int main() { int arr[] = {1,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1}; int N = 18; int *front, *last; front = arr; last = arr + N; while(front <= last) { while( (front < last) && (*front == 0...

Displaying large sorted lists in WPF QUICKLY?

I am developing a program that should be able to display long (up to 500 items) lists of data that need to be resorted when their contents change. Essentially, I have a viewmodel with an observable collection that contains classes with observable data bound to the gui, which is displayed in a ListView. The data must be sorted, but the ...

Sorting array of objects by two criterias?

I have an array of objects that i want to sort by two keys. The objects lets say are of type Student and the properties that i'm intrested in for my sort are grade and name. Student { double grade; string name; ... } How can i sort the objects first by grade and then by name? so for example if i have the list: Tom 9.9 And...

Generics and sorting in Java

Suppose you write a static function in Java to sort an array, much like Arrays.sort(). The problem with Arrays.sort() is that it receives an array of Object, and throws a ClassCastException if its elements don't implement Comparable. So you want your function to receive as an argument an array of a subtype of Comparable. Something like ...

sorting vector in java

I cant find any sorting function in the java API for vectors. Collections.sort is only for List and not for Vector I dont want to write my own sorting algo because I think java should implement this Im looking for something like, class ClassName implements Comparator ... ClassName cn; sort(cn); ...

C# Convert ArrayList Custom Sort to Generic List<T> Custom Sort

Hi, I have an ArrayList of objects that I need to sort in two different fashions, depending on the situation. I followed this example: http://codebetter.com/blogs/david.hayden/archive/2005/03/06/56584.aspx on how to create a PersonComparer by overloading the IComparer object. I liked this method because it allowed me to build an enum...

How to compute the absolute minimum amount of changes to convert one sortorder into another?

Goal How to encode the data that describes how to re-order a static list from a one order to another order using the minimum amount of bytes possible? Original Motivation Originally this problem arose while working on a problem relaying sensor data using expensive satellite communication. A device had a list of about 1,000 sensors th...

Pythonic way to sort list of objects by a dict value (by key) contained within the object

I'm seeking advice on doing the following in a more pythonic way. Consider: class MyObj(object): def __init__(self): self.dict_properties = {} Suppose I've got a list which contains multiple MyObj instances: mylist = [<__main__.MyObj object at 0x1005e3b90, ...] Now i want to sort mylist based on the value of a certain ...

PHP: How to sort values of an array in alphabetical order?

I want to sort values of an array in alphabetical order in PHP. If all values started with same character then they should be sorted using second character and so on. Ignore case sensitive. For Example: before: values[0] = "programming"; values[1] = "Stackoverflow"; values[2] = "question"; values[3] = "answers"; values[4] = "AA Systems...

Javascript sort help

I'm trying to sort some xml into different arrays and I'm a bit stuck on how to go about this. Here is the xml: http://pastebin.ca/1754892 I'm using this xpath expression to get every "series" element that contains at least one "item" child node. var ceerez = theXML.evaluate( '//series[item]' ,theXML, null, XPathResult.ORDERED_NODE_S...

File creation time

How do I sort a directory by file creation, latest first in PHP 5.2? I am on Windows 2000. ...

Sort a file with huge volume of data given memory constraint

Points: We process thousands of flat files in a day, concurrently. Memory constraint is a major issue. We use thread for each file process. We don't sort by columns. Each line (record) in the file is treated as one column. Can't Do: We cannot use unix/linux's sort commands. We cannot use any database system no matter how light t...

Sorting CSV in Python

I assumed sorting a CSV file on multiple text/numeric fields using Python would be a problem that was already solved. But I can't find any example code anywhere, except for specific code focusing on sorting date fields. How would one go about sorting a relatively large CSV file (tens of thousand lines) on multiple fields, in order? Py...

Custom sort with FastObjectListview is not working.

Hey, I'm using the FastObjectListview and now I need to sort on 2 columns. So I tried using the example I found on the ObjectListview website but I can't get it to work. class MyCustomSortingDataSource : FastVirtualListDataSource { override public void SortObjects(OLVColumn column, SortOrder order) { // do some amazing sor...

Categorize a list of lists by 1 element in python

An example list of lists: [ ["url","name","date","category"] ["hello","world","2010","one category"] ["foo","bar","2010","another category"] ["asdfasdf","adfasdf","2010","one category"] ["qwer","req","2010","another category"] ] What I wish do to is create a dictionary -> category : [ list of entries ]. The resultant dictionary would...

Separating output by line alphabetically

I have the code below that outputs the names of files in a directory. I'd like to separate the file names alphabetically by an additional line space when the first letter of the file changes (say from A to B). Any ideas? Thanks. $dirs = scandir("Dir"); foreach($dirs as $file) { if...

How can I order by attributes of multiple subclasses that inherit from the same base class in Ruby on Rails?

I have 4 classes - Patient, Doctor, Person, and Appointment. Patient and Doctor are subclasses of Person. Appointment belongs to Patient and belongs to Doctor. I want to write an AR statement to sort appointments by the patient's last name and another to sort by the doctor's last name, as all appointments will be in a sortable table. ...