Top Up Prev Next Bottom Contents Index Search

3.6 List Classes

The StringList class is privately derived from the SequentialList class, an extremely useful class used throughout Ptolemy. This class implements a linked list with a running count of the number of elements. It uses the generic pointer technique, with

typedef void* Pointer Thus, items in a sequential list can be pointers to any object, with a generic pointer used to access the object. In derived classes, like StringList, this generic pointer is converted to a specific type of pointer, like const char*. The methods are summarized in table

An important point to keep in mind when using a SequentialList is that its destructor does not delete the elements in the list. It would not be possible to do so, since it has only a generic pointer. Also, note that random access (by element number, or any other method) can be very inefficient, since it would require sequentially chaining down the list.

SequentialList has an iterator class called ListIter. The ++ operator (or next member function) returns a Pointer.

In table 3-11 are two classes privately derived from SequentialList, Queue and Stack. The first of these can implement either a first-in, first-out (FIFO) queue, or a last-in, first-out (LIFO) queue. The second implements a stack, which is also a LIFO queue.

Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.