Top Up Prev Next Bottom Contents Index Search

1.7 Other generic container classes


The file DataStruct.h defines two other generic container classes that are privately derived from SequentialList: Queue and Stack. Class Queue may be used to implement a FIFO or a LIFO queue, or a mixture. Class Stack implements a stack.

1.7.1 Class Queue

The constructor for class Queue builds an empty queue. The following four functions move pointers into or out of the queue:

void putTail(Pointer p);
void putHead(Pointer p);
Pointer getHead();
Pointer getTail();
In addition, put is a synonym for putTail, and get is a synonym for getHead. All these functions are implemented on top of the (hidden) SequentialList functions. The SequentialList functions size and initialize are re-exported (that is, are accessible as public member functions of class Stack).

1.7.2 Class Stack

The constructor for class Stack builds an empty stack. The following functions move pointers onto or off of the stack:

void pushTop(Pointer p);
Pointer popTop();
pushBottom(Pointer p);
pushTop and popTop are the functions traditionally associated with a stack; pushBottom adds an item at the bottom, which is non-traditional. The following non-destructive function also exists:

Pointer accessTop() const; 
This accesses but does not remove the element from the top of the stack.

All these functions are implemented on top of the (hidden) SequentialList functions. The SequentialList functions size and initialize are re-exported.



Top Up Prev Next Bottom Contents Index Search

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