home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!utcsri!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch
- From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
- Subject: Re: Wanted: Code for sorting a file
- Message-ID: <dmurdoch.364.724437122@mast.queensu.ca>
- Lines: 36
- Sender: news@knot.ccs.queensu.ca (Netnews control)
- Organization: Queen's University
- References: <1992Dec15.135354.10665@htsa.aha.nl>
- Date: Tue, 15 Dec 1992 16:32:03 GMT
-
- In article <1992Dec15.135354.10665@htsa.aha.nl> quintenu@htsa.aha.nl (Quinten Uijldert) writes:
- >Who can E-Mail me some code for sorting a file. The file contains
- >records like this:
- >
- >TYPE
- > RecType = RECORD
- > Name, Street, Zip, Telephone: String;
- > END;
- > FileType = TEXT;
- >
- >VAR
- > Rec: RecType;
- > f: FileType;
- >
- >I Want to sort the file on Rec.Name, but I can't figure it out how
- >to do it.
- >I Use TP 6.0.
-
- You don't say how big the file is. If it's small enough to load the whole
- thing into memory, the easiest way is as follows:
-
- 1. convert your RecType to an object type,
- 2. create a TStringCollection descendant whose KeyOf method returns a
- pointer to the Name field
- 3. read your data file, and insert all the records into your collection
- 4. write the whole collection back to the file.
-
- This isn't the fastest way to sort, but for a file small enough to fit into
- memory (less than 16380 records, 300K total size) you probably wouldn't
- notice any improvements you could make.
-
- For a bigger file, I'd use an external sort package; QSORT (shareware by Ben
- Baker available at lots of ftp sites) works well for me.
-
- Duncan Murdoch
- dmurdoch@mast.queensu.ca
-