Topics |
|
A queue is a sequence where elements are inserted at one end (the tail) and extracted from the other end (the head). Queues work in a first-in, first out (FIFO) format. New nodes are added to the tail of the queue using an insert operation and removed using from the head of the queue using an extract operation.
The Queue class is a generic singly linked list based stack queue. It is a resizable data structure that allocates and de-allocates heap space with every insert and extract operation. The Queue class inherits the Stack class and manages the stack nodes in a first in, first out format. NOTE: Only a template version of the Queue class is implemented. If your application cannot use templates, code this class and the Stack Class directly for the data type being used. Templates were used to allow the queue to handle numerous data types without having to provide a different version for each data type used.
Queue<TYPE>::Queue() - Default class constructor that calls the Stack class default constructor, which then calls the SLListBase base class to construct a new singly linked list.
Queue<TYPE>::Queue(const Queue<TYPE> &X) - Class copy constructor used to copy construct a new list that will contain a copy of the specified list.
void Queue<TYPE>::operator=(const Queue<TYPE> &X) - Overloaded assignment operator use to assign this list to the specified list. Traps assignment to itself and does not support chained assignment.
int Queue<TYPE>::Insert(const TYPE &X) - Public member function used to create a new node having a copy of X for its data and add it on the tail of the queue. Returns true if successful or false if allocation fails.
int Queue<TYPE>::Extract(TYPE &X) - Public member function used to extract a node from the head of the queue. A copy of X is copied in the node after it is detached and before it is deleted from the list. If the queue is empty, X is left untouched. Returns true if successful or false if the queue is empty.
void Queue<TYPE>::Clear() - Public member function used to extract every node from the queue.
TYPE *Queue<TYPE>::Head() - Public member function that returns a pointer to the head node in the queue.
const TYPE *Queue<TYPE>::Head() const - Public member function that returns a pointer to the head node in the queue.