[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] sort



On Dec 29, 2004, at 12:42 PM, James McCartney wrote:

stable sorts are important if you want to do two level sorts. i.e. sort on criteria A and then sort on criteria B. All items with an equal B will then be sorted by A. This will not work with Quicksort.


x = [ [ \b, 2 ], [ \a, 3 ], [ \c, 2 ], [ \b, 1 ], [ \a, 1 ], [ \a, 2 ], [ \c, 1 ] ]
x.mergeSort {|e, f| e[1] <= f[1] };
x.mergeSort {|e, f| e[0] <= f[0] };

x = [ [ \b, 2 ], [ \a, 3 ], [ \c, 2 ], [ \b, 1 ], [ \a, 1 ], [ \a, 2 ], [ \c, 1 ] ]
x.quickSort {|e, f| e[1] <= f[1] };
x.quickSort {|e, f| e[0] <= f[0] };


ok, thanks.

best, adc
--
--
Alberto de Campo
Bergstrasse 59/33
A-8020 Graz, Austria
e-mail : decampo@xxxxxx
--