Experimenting with Linked Lists
Our programs demonstrate general linked lists, using a pointer to the record. Some implementations use an additional pointer to the preceding record. Also, you may find it useful to store a pointer to the last record in the list.
We have used the pointer as part of the same record that is used to store the data. You may prefer to keep the data separate e.g.
type TData = record ProgramID : integer; ProgName : string; ProgrammerID : integer; end; PtrProg = ^TProg; TProg = record Data : TData; Next : PtrProg; end;
In addition to these general ideas, we provide some specific suggestions below.
- Add the following to program LinkedListDemo:
- procedure AppendRecord to add a record to the end of the list.
- a bubble sort for the ProgName field, using as much of the existing code as possible.
- Write a similar program for your own list of records. You could, for example, process contact details, books, music collections or films.
- Write a short demonstration program using a linked list with pointers from each record to both its successor and predecessor.
- Write a linked list using arrays of records, where one field of the record is the index of its successor.