sorting

Topological Sorting using LINQ

I have a list of items that have a partial order relation, i. e, the list can be considered a partially ordered set. I want to sort this list in the same way as in this question. As correctly answered there, this is known as topological sorting. There's a reasonably simple known algorithm to solve the problem. I want a LINQ-like impleme...

Sorting NSStrings of Numbers

So I have an NSDictionary where the keys are years as NSString's and the value for each key is also an NSString which is sort of a description for the year. So for example, one key is "943 B.C.", another "1886". The problem I am encountering is that I want to sort them, naturally, in ascending order. The thing is that the data source of...

Heap Sorting Algorithm

I need the algorithm of HeapSort for sorting the elements of the array, such that all the elements of the array i.e [19 18 14 15 5 7 13 3 8] are in non-decreasing order. ...

How to filter results based on order in Solr?

I need to facet inside n documents which are selected like ... ORDER BY something DESC LIMIT 100 Is that possible with Solr? How? ...

Control sort order of files in zip archive

Description I'm interested in learning if there is any way to control sort order of files inside zip files using standard routines in PHP and/or Java. I'm not primarily interested in using zip/unzip using shell_exec() or similar, but it can be of interest if it provides with an easy to read solution. With sort order it's safe to assum...

Creating a hash of a string thats sortable

Is there anyway to create hashs of strings where the hashes can be sorted and have the same results as if the strings themselves were sorted? ...

Grouping items in an array?

Hey guys, if I have an array that looks like [A,B,C,A,B,C,A,C,B] (random order), and I wish to arrange it into [A,A,A,B,B,B,C,C,C] (each group is together), and the only operations allowed are: 1)query the i-th item of the array 2)swap two items in the array. How to design an algorithm that does the job in O(n)? Thanks! ...

PHP sorting by age and color coding the results?

I have a program which presents a single random selection from the database each time it is run. What I would like to do is have the selections sorted by activity level and then have the selection title shown in a color which represents how active the random selection is. For example: Item 1 is 45 days old, Item 2 is 61 days old and Ite...

Simple Repository Question about Filtering and Sorting

I have a list of products coming from a repository. Simple enough. Now I want to add filtering and sorting. Sorting could happen outside of the repository since there are no efficiency gains doing them inside the repository (guess). I couldn't imagine doing filtering outside of the repository since we only want to load records we car...

Sorting by date in reviews

In many reviews, there's usually a feature to sort by date, helpfulness, etc... Essentially these work by querying a new MySQL line right? For example: $sql = "SELECT * FROM TABLE ORDER BY TimeAdded" $sql = "SELECT * FROM TABLE ORDER BY Helpfulness" Or would there be a better way to do it? Secondly, making pages for reviews. Is it a...

iPhone CoreData - How to fetch results ignoring case?

Hi, Does anyone know how to fetch some results sorting them alphabetically but ignoring case? ...

How to run action on jQuery selected elements in certain order?

I have a HTML table like this: <table> <tr><td>X</td><td>X</td><td class='latest order1'>X</td><td class='latest order4'>X</td></tr> <tr><td>X</td><td>X</td><td class='latest order3'>X</td><td class='latest order2'>X</td></tr> <tr><td>X</td><td>X</td><td class='latest order6'>X</td><td class='latest order5'>X</td></tr> </table> Now...

Sort by display name instead of actual value

Consider this sample model: MODEL_CHOICES = ( (u"SPAM", u"Spam"), (u"XOUP", u"Eggsoup"), ) (snip) type = models.CharField(max_length=4, choices=MODEL_CHOICES) (The actual implementation is domain-specific and in non-English, so this sample has to do.) When building my query, I'd like to sort the results by that...

Sorting lists by date and then order by latest

Hi, I have a list and would like to sort by date then order by latest date first. The code below sorts by date: allFeeds.Sort(delegate(SimplifiedFeedItem p1, SimplifiedFeedItem p2) { return p1.PublishDate.CompareTo(p2.PublishDate); }); allFeeds.ForEach(delegate(SimplifiedFeedItem p) ...

django sort query result by occurrence count

I've got the flowing two models: class Item(models.Model): Name = models.CharField(max_length = 32) class Profile(models.Model): user = models.ForeignKey(User, unique = True) ItemList = models.ManyToManyField(Item, related_name = "user_itemlist") For Item X I want to get a list of Item objects present in ItemList for all...

Sorting an XML file with Qt

Hi how to to sort an XML file using Qt my file look like this : <?xml version="1.0" encoding="UTF-8"?> <project> <task next="2" first="1" name="2" value="name1"/> <task next="3" first="1" name="1" value="name2"/> <task next="4" first="3" name="4" value="name3"/> <task next="4" first="1" name="6" value="name4"/> <t...

Access sorting by 'revision date' of 'individual widget' by customer.

I am trying to run a query with Access. Each customer may have multiple revisions of the same 'widget'. Not all customers require the same revision, e.g. - CustomerA was entered in column 'ID' as 10, 13, and 34 - 34 contains the data I want to see without seeing entry 10 and 13 - each 'ID' has the date it was entered and the same 'widg...

Sorting Lucene docs in Luke

Hi, I want to fire up a query in luke for luncene indexed document. I want to sort the results before they are fetched. What is the lucene syntax to sort the data. I don't need java/or-language-specific code to sort; instead raw lucene syntax to sort the data? Can anyone give me a sample example for sorting by 2 fields in descending o...

First 6 from a foreach .net 2.0

Hi I need to sort a list then take the first 6 in .net 2.0 for example the code below sorts but does not take the first 6 how can i do this? allFeeds.Sort(delegate(SimplifiedFeedItem p1, SimplifiedFeedItem p2) { return -p1.PublishDate.CompareTo(p2.PublishDate); }); allFeeds.ForEach(delegate(SimplifiedF...

How do I sort this list ?

I have a list of lists. List<List<T>> li = { {a1,a2,a3 ... aN}, {b1,b2,b3 ... bN}, ... }; double foo(List<T> list) { // do something // e.g {1,2,3} // it = 1 + 2 + 3 return it; } Now I want to sort li in such a way that higher the foo(x) for a x higher it should appear in a sorted list. What is the best w...