Student help--records, linked lists, sorting 
Author Message
 Student help--records, linked lists, sorting

Having an interest in this newsgroup for a few years, there are still
items that appear to be poorly covered by books and some instructors.
Some of these are addressed in this example program. Only the header
and main body are shown. Should anyone want the source code, send me

Program File_of_Records__Lists_And_Sorting;
{Turbo v6.0  1/15/01
    A file of records (which consist of a random 8 char name and
random age) is created. Seek is used to show the first and last record
in the file. These records are read to a queue type linked list,
sorted alphabetically by name and displayed. This list is now sorted
by decreasing age. It should be noticed that those of same age are in
alphabetic order. The heap is recovered and the option is given to
"APPEND" more records to the file and repeat the above.
    The file is erased before exiting the program.
    If you compile this program you will have about 280K more bytes in
the heap than if you run from the IDE. }

****************************** snip ************************

BEGIN  {main}
     Randomize;
     memav := MemAvail; {original heap available}
Repeat
     Writeln;
     OpenFile(fRec);
     FileRecords(fRec);

     Write('The last record number is ', FileSize(fRec) - 1, ', ');
     Seek(fRec, FileSize(frec) - 1);   Read(fRec, single);
     Writeln(single.name, ' ', single.age);

     Write('The first record number is 0, ');
     Seek(fRec, 0);    Read(fRec, single);
     Writeln(single.name, ' ', single.age);

     FileToQueue(fRec, head, tail);
     Close(fRec);

     Sort(head, ByName);
     Writeln('Alphabetically sorted:');
     ShowList(head);

     Sort(head, ByAge);
     Writeln('Sorted by decreasing age:');
     ShowList(head);

     Writeln;
     RecoverHeap(head);
     Writeln('Original heap = ', memav, '  now: ', MemAvail);
     Write('More? (Any key/N) ');   Readln(ch);
Until UpCase(ch) = 'N';
     Erase(fRec);
END.



Sat, 05 Jul 2003 06:00:27 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. HELP: Sorting Linked List Data Structures

2. need help with sorting linked list

3. Help Sorting with Pointers and Linked Lists

4. Help Sorting Linked List

5. HELP: Sorting linked list structures

6. Record Link List Help please

7. Sorting a linked list by multiple criteria

8. Sorting Linked Lists

9. Sorting a doubly-linked list?

10. Sorting linked lists

11. Sorting A Linked List?

12. Sorting linked list

 

 
Powered by phpBB® Forum Software