Re: Combining single-key sorts to form concatenated-key sort

From: David Cressey <david_at_dcressey.com>
Date: Mon, 05 Feb 2001 02:33:21 GMT
Message-ID: <Rhof6.35191$2X4.95442_at_petpeeve.ziplink.net>


Sort algorithms can be classified into "stable" and "not stable". Stable sorting algorithms have the nice property that two records with the same sort key value will remain in the original order after the algorithm finishes.

If your single key sort is stable, then you can achieve a multi key sort by a succession of single key sorts, each one on a different column. The trick is that you have to sort first on the most minor sort key, and progress upwards toward the major sort key, which is done on the last pass.

Of course, since this requires multiple passes through the sorter, it can take a long, long time.

--
Regards,
    David Cressey
    www.dcressey.com
"Frog2" <FrogRemailer_at_NoReply.Invalid> wrote in message
news:NJB1JYZE36925.3276388889_at_frog.nyarlatheotep.org...

> I'm trying to sort some records. Each record consists of three data fields
I wish to use
> as a concatenated key for sorting purposes and some detail fields. All
three key fields
> are alphanumeric. All key fields in every record will always contain a
value (no NULLs).
>
> Here's the problem: the language I'm using has a sort function but that
function will
> only let me sort on *one* field of my choice, not all three at once.
Received on Mon Feb 05 2001 - 03:33:21 CET

Original text of this message