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.

  TData = record
    ProgramID : integer;
    ProgName : string[15];
    ProgrammerID : integer;

  PtrProg = ^TProg;
  TProg = record
    Data : TData;
    Next : PtrProg;

In addition to these general ideas, we provide some specific suggestions below.

  1. 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.
  2. Write a similar program for your own list of records. You could, for example, process contact details, books, music collections or films.
  3. Write a short demonstration program using a linked list with pointers from each record to both its successor and predecessor.
  4. Write a linked list using arrays of records, where one field of the record is the index of its successor.
Programming - a skill for life!

Introduction to linked lists including arrays of records