sorting

How do I implement quicksort using a batch file?

While normally it's good to always choose the right language for the job, it can sometimes be instructive to try and do something in a language which is wildly inappropriate. It can help you understand the problem better. Maybe you don't have to solve it the way you thought you did. It can help you understand the language better. May...

How can I sort a 2-D array in MATLAB with respect to one column?

I would like to sort a matrix according to a particular column. There is a sort function, but it sorts all columns independently. For example, if my matrix data is: 1 3 5 7 -1 4 Then the desired output (sorting by the first column) would be: -1 4 1 3 5 7 But the output of sort(data) is: -1 3 1 ...

Best place to Sort a List of Tasks

Hi, Im building a web application which is a process management app. Several different employee types will be shown a list of Tasks to do and as each one completes a task then it is moved on to the next employee to work on. The Task hierarchy is Batch > Load > Assembly > Part > Task. There are currently 8 rules for determining which T...

Sorting nvarchar column as integer

Hi all. I have mixed data i nvarchar column (words and numbers). Which is fastest way to sort data in this column in Numeric Order. Result example: 1 2 3 ... 10 11 ... aaaa aaab b ba ba ... ...

Near Sorting Algorithms - When to use?

From time to time I browse the web and look for interesting algorithms and datastructures to put into my bag of tricks. A year ago I came across the Soft Heap data-structure and learned about near sorting. The idea behind this is that it's possible to break the O(n log n) barrier of compare based sorts if you can live with the fact that...

How do I sort a file in place using bash shell?

I have a file temp.txt, that I want to sort with the "sort" command in bash. I want the sorted results to replace the original file. This doesn't work for example (I get an empty file): sortx temp.txt > temp.txt Can this be done in one line without resorting to copying to temporary files? EDIT: The -o option is very cool for sort. ...

Dynamic Sorting within SQL Stored Procedures

This is an issue that I've spent hours researching in the past. It seems to me to be something that should have been addressed by modern RDBMS solutions but as yet I have not found anything that really addresses what I see to be an incredibly common need in any Web or Windows application with a database back-end. I speak of dynamic sor...

Unicode Characters that can be used to trick a string sorter?

Since Unicode lacks a series of zero width sorting characters, I need to determine equivalent characters that will allow me to force a certain order on a list that is automatically sorted by character values. Unfortunately the list items are not in an alphabetical order, nor is it acceptable to prefix them with visible characters to ensu...

VBA array sort function?

I'm looking for a decent sort implementation for arrays in VBA. A Quicksort would be preferred. Or any other sort algorithm other than bubble or merge would suffice. Please note that this is to work with MS Project 2003, so should avoid any of the Excel native functions and anything .net related. ...

Natural Sort in MySQL

Is there an elegant way to have performant, natural sorting in a MySQL database? For example if I have this data set: Final Fantasy Final Fantasy 4 Final Fantasy 10 Final Fantasy 12 Final Fantasy 12: Chains of Promathia Final Fantasy Adventure Final Fantasy Origins Final Fantasy Tactics Any other elegant solution than to split up th...

Is timsort general-purpose or Python-specific?

Timsort is an adaptive, stable, natural mergesort. It has supernatural performance on many kinds of partially ordered arrays (less than lg(N!) comparisons needed, and as few as N-1), yet as fast as Python's previous highly tuned samplesort hybrid on random arrays. Have you seen timsort used outside of CPython? Does it ...

How do I sort in a Flex AdvancedDataGrid - callback isn't being called

I have an AdvancedDataGrid that uses customer grouping of data. Not all of the groups will be at the same level in the hierarchy, and groups can contain both groups and members. We have a sort callback, but it's not being called except for groups at the leaf-most levels. See code below for an example -- expand all of the groups, then cli...

Sorting a collection in classic ASP

It's quite a simple question - how do I sort a collection? I've got a CSV file with rows in a random order. I'd like to sort the rows according to the date in one column. Do I add the rows to a recordset? Can I sort with a Scripting.Dictionary? I've clearly been spoilt with .NET and Linq, and now I find myself back in the land of class...

Scriptaculous sortable matrix

Hi all! I am trying to create a sortable image matrix, 5x5 using scriptaculous javascript library by I can't make it work. I am trying using a table but I am having trouble linking the <td> into the Sortable object. Do you guys have any hint or documentation I can go through to create this ? Thanks ...

Programmatically Sort Start Menu

I'm looking to sort the start menu alphabetically using C#. I've read about deleting the registry key HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder but when I tried it on my machine it doesn't appear to do much of anything. Does anyone have any other ideas as to what must be done in order to sort the Start Menu? ...

WPF Bind to a Collection of objects, sorted by IDs stored in order in another Collection in C#

For those of you that like puzzles: I had this problem recently and am sure there must be a nicer solution. Consider : an ObservableCollection of Foo objects called foos. Foo contains a string ID field I have no control over foos foos will be changing Then: I have another collection called sortLikeThis sortListThis contains string...

Sorting sets of ordered linked lists

I'm looking for an elegant, high performance solution to the following problem. There are 256 linked lists. Each list contains the same types of object that among other things holds a whole number that is used to define a sort order. All numbers across all lists are unique Each individual list is sorted in ascending order by these ...

Choosing a pivot for Quicksort?

When implementing Quicksort one of the things you have to do is choose a pivot. But when I look at pseudocode like the one below. It is not clear how is should choose the pivot. First element of list? Something else? function quicksort(array) var list less, greater if length(array) ≤ 1 return array select an...

How to rank a million images with a crowdsourced sort

I'd like to rank a collection of landscape images by making a game whereby site visitors can rate them, in order to find out which images people find the most appealing. What would be a good method of doing that? Hot-or-Not style? I.e. show a single image, ask the user to rank it from 1-10. As I see it, this allows me to average the ...

Order dates by upcoming

So I build an array of various dates. Birthdays, anniversaries, and holidays. I'd like to order the array by which one is happening next, essentially sort October to September (wrapping to next year) so if my array is $a = ([0]=>"1980-04-14", [1]=>"2007-06-08", [2]=>"2008-12-25", [3]=>"1978-11-03") I'd like to sort it so it is ar...