sorting

C++ string sort like a human being?

I would like to sort alphanumeric strings the way a human being would sort them. I.e., "A2" comes before "A10", and "a" certainly comes before "Z"! Is there any way to do with without writing a mini-parser? Ideally it would also put "A1B1" before "A1B10". I see the question "Natural (human alpha-numeric) sort in Microsoft SQL 2005" with ...

ruby on rails, searchlogic and refactoring

Hey all, I'mt not too familiar with searchlogic plugin for rails (I did view the railscasts but wasn't helpful in relation to the specific code below). Can anyone briefly describe how it is being used in the three methods below? Thanks for any response. def extract_order @order_by = if params[:order].present? field = params[:order]...

C# - System.StackOverflowException with Lambda

Under what situations would this code error out with System.StackOverflowException? Accounts.Sort((x, y) => string.Compare(x.AccountId, y.AccountId)); Update: the property is written as: public string AccountId { get { return _accountId; } set { _accountId = value; } } Nothing special going on at all. ...

Template Sort In C++

Hey all, I'm trying to write a sort function but am having trouble figuring out how to initialize a value, and making this function work as a generic template. The sort works by: Find a pair =(ii,jj)= with a minimum value = ii+jj = such at A[ii]>A[jj] If such a pair exists, then swap A[ii] and A[jj] else b...

Java Date sorting method?

Hi, I have an String array of dates in the format ex:'2010-05-04 11:26:46 +0530'. How can I check whether a particular date in the array is > today? thanks ...

Fastest sort of fixed length 6 int array

Answering to another StackOverflow question (this one) I stumbled upon an interresting sub-problem. What is the fastest way to sort an array of 6 ints ? As the question is very low level (will be executed by a GPU): we can't assume libraries are available (and the call itself has it's cost), only plain C to avoid emptying instruction ...

LINQ Quicksort is Unstable Except When Cascading

On page 64 of "LINQ To Objects Using C# 4.0" (Tony Magennis) he states that LINQ's quicksort ordering algorithm is unstable... ...although this is simply solved by cascading the result into a ThenBy or ThenByDescending operator. Huh? Why would cascading an unstable sortation into another sortation fix the result? In fact, I'...

Need help with jquery sorting

I have a column within which are multiple 'records' (each a div). Each record has a bunch of fields (each a span whose id is the fieldname). I want to allow the user to sort all the records based on a field. I also want, the field that has been sorted to be moved to the beginning of the record. So I came up with this. But its really sl...

haskell sorting

Hello, How can it be done in most simply way to write (or maybe there is something embedded in haskell) function which takse as arguments list of tuples (String, Int) and Int x and return top x tuples as list according to x value. I wonder if its possible to write a function which also takes 3 argument which is the name of (or index) ...

Sort XML nodes with PHP

I have a serialized string comming in with POST: $imgdata = $_POST['imgdata']; // li[]=2&li[]=3&li[]=1&li[]=4 In this example 001 is reordered after 003 How can I update my XML file with this new order? I think I need simpleXML or xpath. Here are my thoughts: // 1. load xml string $xml = simplexml_load_file('test.xml'); /* <?xml vers...

What Sorting Algorithm Is Used By LINQ "OrderBy"?

Evidently LINQ's "OrderBy" had originally been specified as unstable, but by the time of Orca it was specified as stable. Not all documentation has been updated accordingly - consider these links: Jon Skeet on OrderBy stability Troy Magennis on OrderBy stability But if LINQ's OrderBy is now "stable," then it means it is not using a ...

How do I sort a hash table in javascript?

I have a javascript hash table, like so: var things = [ ]; things["hello"] = {"name" : "zzz I fell asleep", "number" : 7}; things["one"] = {"name" : "something", "number" : 18}; things["two"] = {"name" : "another thing", "number" : -2}; I want to sort these into order by name, so if I iterate through the hash table it will go in order...

sort outer array based on values in inner array, javascript

I have an array with arrays in it, where I want to sort the outer arrays based on values in a specific column in the inner. I bet that sounded more than a bit confusing, so I'll skip straight to an example. Initial data: var data = [ [ "row_1-col1", "2-row_1-col2", "c-row_1-coln" ], [ "row_2-col1", "1-row_2-c...

Sort a 2D Points List (first by X and then Y)

I am trying to sort a List of 2D Points first by x co-ordinate and then by y co-ordinate. I implemented the IComparer interface as follows: class PointComparer : IComparer<Point> { public int Compare(Point x, Point y) { if (x.Y != y.Y) { return x.Y - y.Y; } else { r...

Sort database entries via a dropdown list

Hello! I'm curious if anyone could possibly help me, because I can't find anything exactly related to it anywhere, and it's driving me nuts. I'd like to have a dropdown list on a page, that will give the visitor the option to sort all entries by year. I have entries from i.e. 2001, 2005, 2009, 2010. The years should be displayed in the ...

How can I sort an NSTableColumn of NSStrings ignoring "The " and "A "?

I've got a simple Core Data application that I'm working on to display my movie collection. I'm using an NSTableView, with it's columns bound to attributes of my Core Data store through an NSArrayController object. At this point the columns sort fine(for numeric values) when the column headers are clicked on. The issue I'm having is...

Django: Applying Calculations To A Query Set

I have a QuerySet that I wish to pass to a generic view for pagination: links = Link.objects.annotate(votes=Count('vote')).order_by('-created')[:300] This is my "hot" page which lists my 300 latest submissions (10 pages of 30 links each). I want to now sort this QuerySet by an algorithm that HackerNews uses: (p - 1) / (t + 2)^1.5 p ...

Sorting 2D array of chars C++

I have a 2d array of chars where in each row I store a name... such as this: J O H N P E T E R S T E P H E N A R N O L D J A C K How should I go about sorting the array so that I end up with A R N O L D J A C K J O H N P E T E R S T E P H E N These is a 2d array of chars..... no strings or char points..... ...

natural sort of text and numbers, JavaScript

I'm looking for the easiest way to sort an array that consists of numbers and text, and a combination of these. E.g. '123asd' '19asd' '12345asd' 'asd123' 'asd12' turns into '19asd' '123asd' '12345asd' 'asd12' 'asd123' This is going to be used in combination with the solution to another question I've asked here. The sorting functi...

C++ sort array of strings

I am trying to sort an array of strings, but it's not sorting anything.... what am I doing wrong? string namesS[MAX_NAMES]; int compare (const void * a, const void * b){ return ( *(char*)a - *(char*)b ); } void sortNames(){ qsort(namesS, MAX_NAMES, sizeof(string), compare); } ...