Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!mips!apple!stadler From: stadler@Apple.COM (Andy Stadler) Newsgroups: comp.sys.mac.hypercard Subject: Re: Complex sorting in Supercard 1.5 Message-ID: <54102@apple.Apple.COM> Date: 18 Jun 91 01:26:02 GMT References: Organization: Apple Computer Inc., Cupertino, CA Lines: 40 In article mg2x+@andrew.cmu.edu (Michael Andrew Gelman) writes: >I'm working in SuperCard, but I think that HyperCard works the same way >(at least the older HyperCard). I could be wrong, though, but I'll take >any clue. > >I've got this stack that has four fields on it, F1...F4. I need the >stack sorted by all the fields, that is first by F1, then by F2, etc. > > [...describes a method for multi-key sorts which doesn't work...] > >Has anyone run across this? Can anyone see a solution? As has been described on this board before, HyperCard supports a simple yet powerful technique for multiple-key sorts. Just sort and resort the stack, using each key, in order of "importance" from last to first. To sort your example, you would write: on multiSort sort by bkgnd field f4 sort by bkgnd field f3 sort by bkgnd field f2 sort by bkgnd field f1 end multiSort Choice of sort modifiers (sort by numeric, sort descending, etc) is left to the reader. The key to this technique is that HyperCard religiously adheres to the concept of a "stable sort". This means that if you sort two items whos keys match, the items will remain in the same relative order after sorting. Not all sorting algorithms do this, because for the most simple sorts, you don't have to. I don't know anything about SuperCard 1.5. But I certainly hope that SC's sort is stable, and if it is, this technique should work just fine there, too. Andy Stadler Apple Computer, Inc.