sorting

Pecking order of pigeons?

I was going though problems on graph theory posted by Prof. Ericksson from my alma-mater and came across this rather unique question about pigeons and their innate tendency to form pecking orders. The question goes as follows: Whenever groups of pigeons gather, they instinctively establish a pecking order. For any pair of pigeons...

mysql query results sorting

I am calling the results form a query to a list on my site based on if the item is "downtown_hosted". This works fine but I would now like to sort that list DESC, but can't seem to get the syntax correct. Below is what I have: $result_events = mysql_query("SELECT * FROM events WHERE downtown='downtown_...

Utility of List<T>.Sort() versus List<T>.OrderBy() for a member of a custom container class

I've found myself running back through some old 3.5 framework legacy code, and found some points where there are a whole bunch of lists and dictionaries that must be updated in a synchronized fashion. I've determined that I can make this process infinitely easier to both utilize and understand by converging these into custom container cl...

NullPointerException in Java bubblesort with acm dialog

Hi, the program gives following exception: Exception in thread "main" java.lang.NullPointerException at myclasses.BubbleSort.run(BubbleSort.java:42) at acm.program.Program.runHook(Program.java:1519) at acm.program.Program.startRun(Program.java:1508) at acm.program.Program.start(Program.java:729) at myclasses.BubbleS...

How to get MAX value of a version-number (varchar) column in T-SQL

I have a table defined like this: Column: Version Message Type: varchar(20) varchar(100) ---------------------------------- Row 1: 2.2.6 Message 1 Row 2: 2.2.7 Message 2 Row 3: 2.2.12 Message 3 Row 4: 2.3.9 Message 4 Row 5: 2.3.15 Message 5 I want to write a T-Sql query that will get ...

Adding additional sorting attributes to array of records...then sorting!

Let's say I run an ActiveRecord query and it returns 3 results, with a bunch of attributes. I want to add 3 attributes to each record in the Array so I can do sorting at a code-level. These 3 include: num_comments, num_views, last_view. How do I add these attributes? How do I then sort the records, in order of precendence, by num_comm...

Overriding Ruby's spaceship operator <=>

I am trying to override Ruby's <=> (spaceship) operator to sort apples and oranges so that apples come first sorted by weight, and oranges second, sorted by sweetness. Like so: module Fruity attr_accessor :weight, :sweetness def <=>(other) # use Array#<=> to compare the attributes [self.weight, self.sweetness] <=> [other.we...

How can i sort Generic list with Linq?

How can i sort myScriptCellsCount.MyCellsCharactersCount (list int type) in linq public class MyExcelSheetsCells { public List<int> MyCellsCharactersCount { get; set; } public MyExcelSheetsCells() { MyCellsCharactersCount = new List<int>(); } } void ArrangedDataList(DataTabl...

sort Ienumerable list

I have the following list IEnumerable<Car> cars The Car object has a model and a year. I want to sort this list by model and then year (within model) what is the best way of doing this ? ...

Is it possible to split a sequence of numbers into two groups based in median value without sorting?

Is there an algorithm to split a sequence of random numbers into two groups based on a median value determined on the fly(without sorting them)? Ex. If I have the sequence 2-3-6-7-1-4-5, the result would be two separated groups: A) 1 2 3 B) 5 6 7 Median value: 4 ...

Efficient method to calculate the rank vector of a list in Python

I'm looking for an efficient way to calculate the rank vector of a list in Python, similar to R's rank function. In a simple list with no ties between the elements, element i of the rank vector of a list l should be x if and only if l[i] is the x-th element in the sorted list. This is simple so far, the following code snippet does the tr...

Thinking_sphinx sorting through associations

I am trying to sort the search results of a thinking_sphinx search. The columns I want to sort are in associated tables: class Membership < ActiveRecord::Base define_index do indexes :title indexes user.first_name, :as => :first_name indexes user.last_name, :as => :last_name has :organization_id, :active set_property...

Best way to sort a long list of strings

I would like to know the best way to sort a long list of strings wrt the time and space efficiency. I prefer time efficiency over space efficiency. The strings can be numeric, alpha, alphanumeric etc. I am not interested in the sort behavior like alphanumeric sort v/s alphabetic sort just the sort itself. Some ways below that I can t...

Java: Sorting a HashMap

Possible Duplicate: How to sort a Map<Key, Value> on the values in Java? I have a HashMap of the type: HashMap<String, Integer> h = new HashMap<String, Integer>(); The HashMap contains a list of Strings and the Integer is a counter for the number of times that String has been found. What I would like to be able to do is sor...

Jface tableviewer multi sort columns

dear all, i am implementing a tableviewer that is able to sort values depengin on their column order. e.g. column1-column2-columnX sorts the rows first on the values of column 1, then column 2, column.... Therefore i want to use a ColumnViewerSorter, especially the method "int doCompare(Viewer viewer, Object e1, Object e2);" inside t...

Drupal 6: sorting specific date chronologically...

Hi friends, I'm a drupal newbie... I have created a block with View Module to list events (title, event date) at homepage. dates are being entered into textbox and such format as below; December 5-7, 2010 December 4-6, 2011 July 17-19, 2011 ... When I set Sort Criteria as date, it just mess :/ it doesn't sort chron...

How to sort an array of objects(Points) in Java?

Hi, So I wanna sort an array of Points using the built in sorting method, by a specific coordinate, say x. How can I do this? Heres a sample code: Point A[] = new Point[10]; // ... Initialize etc. Arrays.sort(A, x-coordinate); Is there a built-in comparator for x-coordinates in Point Class? If not, how can I create one and use it. An...

wordpress sort search results by date .

Is there any special parameter that i can pass to search url to sort it by date . And is there any parameter to increase the number of search results returned ? Thanks ...

'Natural sorting' with MySQL?

I'm trying to query a Wordpress database and get the post titles to sort in a correct order. The titles are formatted like this: Title 1, Title 2.. I need to sort them in ascending order, how can I do this? If I just sort them ascending they will come out like: 1,10,11... Right now my order by statement is this but it does nothing: ORD...

Sorting arrays in Java using the flag-sort

Write a static method in Java : public static void sortByFour (int[] arr) That receives as a paramater an array full of non-negative numbers (zero or positive) and sorts the array in the following way : In the beginning of the array all the numbers that devide by four without a remainder will appear. After them all the numbers in th...