Board index » delphi » Help with sorting a file of records

Help with sorting a file of records

Quote
Stephen Wales wrote:

> What I need to be able to do is read in this file and sort it on the
> three key fields, in order.

Sprint to the nearest library (preferably a university library), and
look up

  Donald Knuth
  The Art of Computer Programming, vol. 3, Sorting and Searching
  Addison Wesley, 1973

That's your definitive reference.

BTW., Knuth has a little discussion on using the word "order":

  "Since only two of our tape drives were in working order, I was
  ordered to order more more tape units in short order, in order
  to order the data several orders of magnitude faster."

(But he considers other words to be even more overused.)

- Alf

 

Re:Help with sorting a file of records


I've been playing around with TP 7.0 at home.  I'm rusty at Pascal so I'm
in search of some help.

I have created a file of records in the format:

record
  key1 : char
  key2 : char
  key3 : string[50]
  datafield
  datafield
  etc
end

What I need to be able to do is read in this file and sort it on the
three key fields, in order.

For example if I had

B,1,xyz,data
B,1,abc,data
A,2,ser,data
B,2,dfg,data

after the sort it would look like:

A,2,ser,data
B,1,abc,data
B,1,xyz,data
B,2,dfg,data

I looked around the SWAG archives for a routine - I found one that sorts
a file of records on one key and uses pointers to do it.

I'm *real* rusty on pascal pointers, and it was only 1 key, not 3.

Speed is not an issue, it's a program for personal use only.

Thanks for any help.
Steve.
--
| | | | | |   Stephen Wales               | Internet: steph...@mincom.com
| | | | | |   Analyst Programmer, MIMS/HR | ** Aussie in exile **
| | | | | |   Mincom, Inc.                |
|M|I|N|C|O|M  Denver, Colorado, U.S.A.    | No employer opinion included

Re:Help with sorting a file of records


I'd start off by creating an array of string with an element for each
record to sort, and concatenate the two chars and the string into this
array.  Then you can sort this array quite easily, and then re-order the
original data accordingly.

        -Ben Jones-

    <alb...@cix.compulink.co.uk>

Quote
>>>  Come visit the WaistWear homepage!   <<<
> at http://www.compulink.co.uk/~waistwear/ <

Other Threads