text cover

Data Abstraction and Problem Solving with C++

Walls and Mirrors

by Frank M. Carrano

Addison Wesley Logo

QueueA.cpp

Go to the documentation of this file.
00001 
00021 #include "QueueA.h"  // header file
00022 
00023 Queue::Queue() : front(0), back(MAX_QUEUE-1), count(0)
00024 {
00025 }  // end default constructor
00026 
00027 bool Queue::isEmpty() const
00028 {
00029    return count == 0;
00030 }  // end isEmpty
00031 
00032 void Queue::enqueue(const QueueItemType& newItem)
00033    throw(QueueException)
00034 {
00035    if (count == MAX_QUEUE)
00036       throw QueueException(
00037     "QueueException: queue full on enqueue");
00038    else
00039    {  // queue is not full; insert item
00040       back = (back+1) % MAX_QUEUE;
00041       items[back] = newItem;
00042       ++count;
00043    }  // end if
00044 }  // end enqueue
00045 
00046 void Queue::dequeue() throw(QueueException)
00047 {
00048    if (isEmpty())
00049       throw QueueException(
00050     "QueueException: empty queue, cannot dequeue");
00051    else
00052    {  // queue is not empty; remove front
00053       front = (front+1) % MAX_QUEUE;
00054       --count;
00055    }  // end if
00056 }  // end dequeue
00057 
00058 void Queue::dequeue(QueueItemType& queueFront)
00059    throw(QueueException)
00060 {
00061    if (isEmpty())
00062       throw QueueException(
00063     "QueueException: empty queue, cannot dequeue");
00064    else
00065    {  // queue is not empty; retrieve and remove front
00066       queueFront = items[front];
00067       front = (front+1) % MAX_QUEUE;
00068       --count;
00069    }  // end if
00070 }  // end dequeue
00071 
00072 void Queue::getFront(QueueItemType& queueFront) const
00073    throw(QueueException)
00074 {
00075    if (isEmpty())
00076       throw QueueException(
00077     "QueueException: empty queue, cannot getFront");
00078    else
00079       // queue is not empty; retrieve front
00080       queueFront = items[front];
00081 }  // end getFront
00082 // End of implementation file.

Generated on Sun Aug 27 17:20:03 2006 for AWLogo by  doxygen 1.4.6