Re: stable sorting
- Posted by Juergen Luethje <eu.lue at gmx.de> Feb 26, 2003
- 464 views
Hi Kat, you wrote: > On 25 Feb 2003, at 17:02, Juergen Luethje wrote: [...] >> Say I have a list of records with student names and marks, already >> sorted by name. Then i want to sort this list by mark, so that students >> with the same mark remain listed in alphabetical order. > > <snip> > >> Is there a library in the archive, with which this can be achieved? >> I didn't find one. > > Yes, sorttok(). Several examples of sorting multiple fields at the same time > are in the readme.html : See: > http://www.pell.net/warning/ai/strtok-v2-1.html#sorttok Great, thank you! > It handles such things as a descending sort in one field, then an ascending > sort within that sort, and a descending in that sort, etc,, as many internal > sorts as you have fields in the list, mixing up-down sorts as you want. > > If you want your list not sorted, but you want the trace route thru the list > in > the sort order you specify, see sortntok(). The functions are very useful and flexible! I downloaded 'strtok-v2-1.zip' and am very curious to have a closer look at the source code, if I've some more time. Hopefully I'll understand, how it works. > Strtok v2.2 is due out someday in March 2003. Well.. how about making sorttok() and sortntok() (or two additional functions) even more generic? At the moment, one "record" must be a string: sorted = sorttok({"Fred,Astaire,45,Alberta,Canada", "Lucy,Ball,56,Barre,North Dakota", "Red,Skelton,34,London,England", "Pierre,du Pont,12,Paris,France"}, 3, ',') I don't always have comma (or semicolon or whatever) delimeted fields. So wouldn't it be more generic, if one field is an atom or a sequence? E.g.: sorted = sorttok({{"Fred","Astaire",45,"Alberta","Canada"}, {"Lucy","Ball",56,"Barre","North Dakota"}, {"Red","Skelton",34,"London","England"}, {"Pierre","du Pont",12,"Paris","France"}}, 3, ',') > Kat Best regards, Juergen -- /"\ ASCII ribbon campain | \ / against HTML in | Superstition brings bad luck. X e-mail and news, | / \ and unneeded MIME |