sorting

How to apply an alphanumeric sort in XSLT

Based on the following XML, what is the best way to achieve an alphanumeric sort in XSL? Edit: to clarify, the XML below is just a simple sample the real XML would contain much more variant values. <colors> <item> <label>Yellow 100</label> </item> <item> <label>Blue 12</label> </item> <item> <label>Orange 3</label...

how to sort hash map

how we will be able to sort a hashmap i want so sort in the basis of a value in array list... thanx in advance.............. ...

Creating a tree from a list of tuples

I seem to be blind at the moment, so I need to ask here. I want to sort a list of tuples which look like that (id, parent_id, value) So that it is a representation of the tree as a flattend list of list of tree nodes. For example the input (1, None, '...') (3, 2', '...') (2, 1, '...') (4, 1, '...') (5, 2, '...') (6, None, '...') S...

How to Sort Integer Strings?

I am facing a strange problem while sorting a list of strings with integer values. However some values could be prefixed with some characters. e.g. // B1, 5, 50, A10, 7, 72, B3, A1, A2 There are basically page numbers and should be sorted like: // A1, A2, A10, B1, B3, 5, 7, 50, 72 But if I use default string sorting then these wil...

Automatically sorting on insert in QTreeWidget

I have a QTreeWidget that I insert items in, and the user can select a column to sort it. As the items are being inserted, they just get appended to the end instead of having the sort being done automatically. If I click the header to switch between ascending/descending it will sort the current items. I figured I could call sortItems() ...

Critique this late night, noob Haskell code

I'm working through Real World Haskell, and at the moment doing the exercises at the end of Chapter 3. I'm taking an unusual approach: even though I know there are some language features they haven't covered yet that would help me, I am trying to do these exercises using only things they have explicitly covered. Why? Just kind of for fu...

How can i perform an insertion sort but check a property of the element in the array not just the element?

Sorry, I'm sure this is simple but I'm tired and can't figure it out. I have an array of elements, each element is in fact a particle which is a data structure (a struct in c) containing, among other things the particles current position (int x,y,z). I want to compare the elements x position not just the element itself. Looking at the...

Sorting a list with qsort?

Hello. I'm writing a program in which you enter words via the keyboard or file and then they come out sorted by length. I was told I should use linked lists, because the length of the words and their number aren't fixed. should I use linked lists to represent words? struct node{ char c; struct node *next; }; And then how can...

Does qsort demand consistent comparisons or can I use it for shuffling?

Update: Please file this under bad ideas. You don't get anything for free in life and here is certainly proof. A simple idea gone bad. It is definitely something to learn from however. Lazy programming challenge. If I pass a function that 50-50 returns true or false for the qsort's comparision function I think that I can effectively...

Sorting by key and value in case keys are equal

The official oauth guide makes this recommendation: It is important not to try and perform the sort operation on some combined string of both name and value as some known separators (such as '=') will cause the sort order to change due to their impact on the string value. If this is the case, then what would be an efficie...

Limitations of comparison based sorting techniques

Comparison sort is opted for in most of the scenarios where data needs to be ordered. Techniques like merge sort, quick sort, insertion sort and other comparison sorts can handle different data types and efficiency with a lower limit of O(nLog(n)). My questions are Are there any limitations of comparison based sorting techniques? Any ...

How to find duplicates in a List<T> quickly, and update the original collection

Let me start by saying I've read these questions: 1 & 2, and I understand that I can write the code to find duplicates in my List, but my problem is I want to update the original list not just query and print the duplicates. I know I can't update the collection the query returns as it's not a view, it's an anonymous type IEnumerable<T>....

Sort Postcode for menu/list

I need to sort a list of UK postcodes in to order. Is there a simple way to do it? UK postcodes are made up of letters and numbers: see for full info of the format: http://en.wikipedia.org/wiki/UK_postcodes But my problem is this a simple alpha sort doesn't work because each code starts with 1 or two letters letters and then is imme...

Algorithm to find the smallest non negative integer that is not in a list

Given a list of integers, how can I best find an integer that is not in the list? The list can potentially be very large, and the integers might be large (i.e. BigIntegers, not just 32-bit ints). If it makes any difference, the list is "probably" sorted, i.e. 99% of the time it will be sorted, but I cannot rely on always being sorted. ...

Sorting in lucene.net

I got my lucene index with a field that needs to be sorted on. I have my query and I can make my Sort object. If I understand right from the javadoc I should be able to doe query.SetSort(). But there seems to be no such method... Sure I'm missing something vital. Any suggestions? ...

sorting array element using javascript

i need program in which you enter words via the keyboard or file and then they come out sorted by length using javascript ...

Efficiently sorting data from DB using Java?

What we have: 3 MySQL DB tables: user, text, friend user: username, password, email, etc. text: username, text, date, etc. friend: username, friend_username, etc. Task: Write an algorithm (in Java) to show 10 latest texts from your friends. Ultimate target is to have running time within O(n log n). DB tables can be modified (adde...

Why does List<T>.Sort method reorder equal IComparable<T> elements?

I have a problem with how the List Sort method deals with sorting. Given the following element: class Element : IComparable<Element> { public int Priority { get; set; } public string Description { get; set; } public int CompareTo(Element other) { return Priority.CompareTo(other.Priority); } } If I try to ...

Fluent sorting of a List<T> on multiple criteria using extension methods?

To sort a List on multiple criteria, I'm currently doing something like: collection.Sort((f1, f2) => { var comp = f1.FirstCriteria.CompareTo(f2.FirstCriteria); return comp != 0 ? comp : f1.SecondCriteria.CompareTo(f2. SecondCriteria); }); But wouldn't it be nice to be able to do something like: collection.MultipleSort(f1.Firs...

Extension Method to Sort a List within a parent object

public class Person { public string name { get; set; } public Email email { get; set; } } public class Email { public string desc { get; set; } } public static IEnumerable<T> Sort<T>(this IEnumerable<T> source, string sortExpression, bool desc) { var param = Expression.Parameter(typeof(T), string.Empty); ...