sorting

Is possible to make the quick sort fuction sort array descending?

I got the following php function, and want to change it into descending sorting, can someone help me: function quickSort(&$numbers, $array_size,$level) { q_sort($numbers, 0, $array_size - 1,$level); } function q_sort(&$numbers, $left, $right,$level) { $l_hold = $left; $r_hold = $right; $pivot = $numbers[$left]; while...

How would I sort a list of files by name to match how Windows Explorer displays them?

Let's say I've sorted a list of files in Explorer by name, like so: 2009-06-02-4.0.9.txt 2009-06-02-4.0.10.txt 2009-06-02-4.0.11.txt 2009-06-02-4.0.12.txt I have a FileInfo Comparer that sorts an array of FileInfo objects by name: class FileInfoComparer : IComparer<FileInfo> { public int Compare(FileInfo x, FileInfo y) { ...

sorting subset of rows in datagridview

I'm trying to hack together a datagridview in c# that can handle hierarchical data (currently just 2 levels) since I couldn't find a 3rd-party control that worked and looked exactly as I needed it to. I've managed to get expand/collapse and global sorting working (sort by top level group, then sort within each group) but I want to add a...

Is json_decode in PHP guaranteed to preserve ordering of elements when returning an array?

You can pass a boolean to json_decode to return an array instead of an object json_decode('{"foo", "bar", "baz"}', true); // array(0 => 'foo', 1 => 'bar', 2 => 'baz') My question is this. When parsing object literals, does this guarantee that the ordering of the items will be preserved? I know JSON object properties aren't ordered,...

Observable Collection Property Changed on Item in the Collection

I have an ObservableCollection. I've bound it to a ListBox control and I've added SortDescriptions to the Items collection on the ListBox to make the list sort how I want. I want to resort the list at ANY point when any property changed on a child element. All my child elements implement INotifyPropertyChanged. ...

Why won't windows explorer sort directories under the 'Temporary ASP.NET Files' directory by name?

When I navigate to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\myfirstproject\202aebd2\f0e764e2\assembly\dl3 in Windows explorer, there are 108 folders with 8 character hexadecimal names. Explorer won't sort this folder by name (or value ). What gives? ...

How do I achieve something like MySQL's latin1_general_ci collation in PHP?

I am writing a string compare function to sort medical terms that often contain special accented characters from many different European languages, and I need to somehow achieve a collation similar to MySQL's latin1_general_ci. First, I'm doing some basic munging on the strings to remove spaces, quotes, hyphens, parentheses, etc. The pr...

How to sort MYSQL fulltext search results by relevancy

Hello, I am relatively new to MYSQL and have had an issue that has been bugging me for a while. I've tried googling all over the place for the answer, but have unable to find an acceptable solution as of yet. Here is the query I am running currently to find the best possible match for a given search term: $query="SELECT * from `vocabu...

XSLT 1.0: sorting between multiple documents

<xsl:for-each select="//filenames"> <xsl:variable name="current_filename" select="."/> <xsl:for-each select=" document(.)//someNode[not( . = document($current_filename/preceding-sibling::node())//someNode )] "> <xsl:value-of select="."/> </xsl:for-each> </xsl:for-each> In the above code (XSLT 1.0), I ...

Tokenizing and sorting with XSLT 1.0

I have a delimited string (delimited by spaces in my example below) that I need to tokenize, sort, and then join back together and I need to do all this using XSLT 1.0. How would I do that? I know I need to use xsl:sort somehow, but everything I’ve tried so far has given me some sort of error. For example, if I run the code at the bot...

Sorting strings containing numbers in a user friendly way

Being used to the standard way of sorting strings, I was surprised when I noticed that Windows sorts files by their names in a kind of advanced way. Let me give you an example: Track1.mp3 Track2.mp3 Track10.mp3 Track20.mp3 I think that those names are compared (during sorting) based on letters and by numbers separately. On the other h...

Sorting arrays in Java

I want to pass 2 arrays to a function in Java and have them sorted in the calling function. How do i use a function to accomplish that? I could have the function return an object with 2 arrays, but is there a non object-oriented solution to this? EDIT : I this particular situation I cant use the inbuilt Array.sort function in Java. ...

List.Sort in C#: comparer being called with null object

I am getting strange behaviour using the built-in C# List.Sort function with a custom comparer. For some reason it sometimes calls the comparer class's Compare method with a null object as one of the parameters. But if I check the list with the debugger there are no null objects in the collection. My comparer class looks like this: pu...

Is there anything like memcached, but for sorted lists?

I have a situation where I could really benefit from having system like memcached, but with the ability to store (per each key) sorted list of elements, and modifying the list by addition of values. For example: something.add_to_sorted_list( 'topics_list_sorted_by_title', 1234, 'some_title') something.add_to_sorted_list( 'topics_list_s...

Using CompareTo() to sort based on multiple columns

Currently I have an object implementing the IComparable interface (ASP.NET 3.5, VB). When I place several instantiated objects into a Generics list, I sort them by doing a simple someList.Sort. My CompareTo() function is this: Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo 'default is...

Need help with my heap sort

I'm kind of stuck with my heap sort here in php: <?php function heapSort($a, $count){ $a = heapify($a, $count); $end = $count - 1; while ($end > 0){ $temp = $a[$end]; $a[$end] = $a[0] ; $a[0]= $temp; $end = $end - 1; siftDown($a, 0, $end); } return $a; } function hea...

Comparison method for sorting that shuffles equal elements randomly

Here's a puzzle for you. I want to change the following comparison method, so that when two items are considered equal, they will be shuffled randomly. myList.Sort( (x, y) => x.Score.CompareTo(y.Score) ); I could imagine that this scenario would be useful when ordering search results if you didn't want to give preference to one resul...

Issues with pagination and sorting

Hi, I'm looking into situations in database-oriented web applications when one should rely on client side sorting of tables over sorting on the server side. One particular situation that is bugging me is pagination. When trying to paginate a large table (say 10000 rows), as well as sort it by a particular column, what would be the best...

Sorting mixed numbers and strings

I have a list of strings that can contain a letter or a string representation of an int (max 2 digits). They need to be sorted either alphabetically or (when it is actually an int) on the numerical value it represents. Example: IList<string> input = new List<string>() {"a", 1.ToString(), 2.ToString(), "b", 10.ToString()}; input.Or...

How to suppress the display of repeating values in html tables which can be sorted?

I have a table in HTML which I am generating from XML/XSL and I want it to suppress repeating values. However, I also want to sort it on the fly by clicking the titles. Without a round trip to the server I need to suppress different values after each sort. Is there a good javascript/css solution. For example Data Date Person Score ...