text cover

Data Abstraction and Problem Solving with C++

Walls and Mirrors

by Frank M. Carrano

Addison Wesley Logo

QueueL.cpp

Go to the documentation of this file.
00001 
00017 #include "QueueL.h"  // header file
00018 
00019 Queue::Queue()
00020 {
00021 }  // end default constructor
00022 
00023 Queue::Queue(const Queue& Q)
00024    : aList(Q.aList)
00025 {
00026 }  // end copy constructor
00027 
00028 Queue::~Queue()
00029 {
00030 }  // end destructor
00031 
00032 bool Queue::isEmpty() const
00033 {
00034    return (aList.getLength() == 0);
00035 }  // end isEmpty
00036 
00037 void Queue::enqueue(const QueueItemType& newItem)
00038    throw(QueueException)
00039 {
00040    try
00041    {
00042       aList.insert(aList.getLength()+1, newItem);
00043    }
00044    catch (ListException e)
00045    {
00046       throw QueueException("QueueException: cannot enqueue item");
00047    }
00048    catch (ListIndexOutOfRangeException e)
00049    {
00050       throw QueueException("QueueException: cannot enqueue item");
00051    }  // end try
00052 }  // end enqueue
00053 
00054 void Queue::dequeue() throw(QueueException)
00055 {
00056    if (aList.isEmpty())
00057       throw QueueException(
00058     "QueueException: empty queue, cannot dequeue");
00059    else
00060       aList.remove(1);
00061 }  // end dequeue
00062 
00063 void Queue::dequeue(QueueItemType& queueFront)
00064    throw(QueueException)
00065 {
00066    if (aList.isEmpty())
00067       throw QueueException(
00068     "QueueException: empty queue, cannot dequeue");
00069    else
00070    {
00071       aList.retrieve(1, queueFront);
00072       aList.remove(1);
00073    }  // end if
00074 }  // end dequeue
00075 
00076 void Queue::getFront(QueueItemType& queueFront) const
00077    throw(QueueException)
00078 {
00079    if (!aList.isEmpty())
00080       throw QueueException(
00081       "QueueException: empty queue, cannot getFront");
00082    else
00083       aList.retrieve(1, queueFront);
00084 }  // end getFront
00085 // End of implementation file.

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