CompuServe Messages

Sorting linked list

    17-Feb-94 19:10:47
Fm: Jim Butterfield 73624,14
To: jack york 71562,3372
The info is a good start, Jack. Now, about those ten fields for each record, and your comment that the computer "can sort on 4 of them". Could you give a little more detail, please? Does the computer continuously have a (sorted) linked list for each index field? Or, do you ask the computer to do a sort on a specific field when you need it? Or, is it really just a multi-field key (thus, surname, and if surname is the same, then city, and if both are the same, then street name… you know the kind of thing). One of the easier ways to do an index is just to write one more sequential file, paralleling your data file. It's a bit like the headings in your phone book .. or, if you like, the "keys" to each volume of an encyclopaedia. Thus, you can say the logical equivalent of: "AAA is record 1, DOE is record 11, HAMPTON is record 21, MURRAY is record 31… ". In such a case, you would know that to find FOGARTY you can start your search at record 11/12, and will find it with 10 comparisons at most, if it's there. It's often true that sequential key files are much shorter than their data equivalents; for that reason, the key file sometimes contains EVERY record. But it doesn't need to. Note also that my above reference to records 11 or 21 do not need to be in numeric sequence; in a linked list, the won't be. Rather, they are just the point at which the list may be entered for searching. And keep in mind that such an index file can be rebuilt very quickly. Just roar through the linked list (no comparisons needed), and make an entry into your index file every tenth (or twentieth, or fiftieth) item. –Jim