
CSci 131 -- Algorithms and Data Structures I
Project #5
Due Date: November 21, 2000
(For your information: Project 6 will be due Dec. 7, the last day of
class.)
The purpose of this project is to give you more practice in dealing with generic packages, and illustrate the advantages of a clearly-specified generic interface in supporting multiple implementations and multiple clients.
In this project you will modify the tables package to support a different implementation of a table.
From Projects 1-4, you now have a tables package that supports active iteration and a CD client program that uses this feature. In this project you will create a new package, Tables_Generic_List, starting with a copy of Tables_Generic and modifying the PRIVATE part of the package, and the body, so that a table is stored as a singly-linked list. The PRIVATE part will look like this:
PRIVATE
SUBTYPE TableSize IS Natural RANGE 0..Capacity;
TYPE ListNode;
TYPE ListPointer IS ACCESS ListNode;
TYPE ListNode IS RECORD
Data: Element;
Next: ListPointer;
END RECORD;
TYPE List IS RECORD
Head: ListPointer;
Tail: ListPointer;
END RECORD;
TYPE TableType IS RECORD
CurrentSize : TableSize := 0;
Data
: List;
END RECORD;
END Tables_Generic_List;
Now rewrite all the operations in the body to take account of this new implementation. Note that InitializeTable is now a nontrivial operation that requires deleting all the nodes in a list, one by one.
You can use the programs in Chapter 8 as starting points for your list operations, but do NOT use any programs from Chapter 9! You need to learn to write linked-list code -- it is very important to your education.