[Gllug] [OT] sort algorithms

James Courtier-Dutton james.dutton at gmail.com
Tue Nov 29 21:34:55 UTC 2011


Hi,

I have a problem with a special sort I need to do.
I have some ideas for an efficient solution, but I wished to ask if
anyone else had a better idea.
My current best solution is to do a transform on the source data using
hash lookups on the predefined sequence.
So the source data is changed into numbers that when sorted are in
numerical order, do a normal numerical sort, and then repeat the
inverse of the transform at the end.

Problem is as follows.
Target pattern is a list of numbers in a certain predefined sequence.
The source data is a set of numbers that is always a subset of the
predefined sequence.
I need a way to sort the source data so that the numbers appear in the
same order as the predefined sequence.

Eg.
Predefined sequence
1  5   8  4  3   6   9

Source data
9 3 4 8 1

Result
1 8 4 3 9

Kind Regards

James
--
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list