最初由 terrence 发布
Keysorting consists of the following steps:
1. Read the input file, one record at a time, storing in an array only the key (course code)and the record’s byte offset. (Note: your array should not hold the full record contents,but just the key)
2. Sort the array in nondecreasing order of key.
3. Using the information in the array, write the records of the output file (sequentially) insorted order by key. Note that after the array is sorted, you will have to go through thearray positions in order. For each position of the array you need to use the byte offsetin order to position and read the record again from the input file, and immediatelywrite the record (sequentially) into the output file with the new format.
Note that in the first step, once you have the byte offset for a record and for the previousrecord, you can calculate the record length, which will be needed when writing the outputrecords in step 3. In C++, you can easily obtain the current get pointer position in a fileusing the method tellg.