SOURCE FILE: QueueA.cpp
// ********************************************************
// Implementation file QueueA.cpp for the ADT queue.
// Circular array-based implementation.
// The array has indexes to the front and back of the
// queue. A counter tracks the number of items currently
// in the queue.
// ********************************************************
#include "QueueA.h" // header file
queueClass::queueClass():
Front(0), Back(MAX_QUEUE-1), Count(0)
{
} // end default constructor
bool queueClass::QueueIsEmpty() const
{
return bool(Count == 0);
} // end QueueIsEmpty
void queueClass::QueueInsert(queueItemType NewItem,
bool& Success)
{
Success = bool(Count < MAX_QUEUE);
if (Success)
{ // queue is not full; insert item
Back = (Back+1) % MAX_QUEUE;
Items[Back] = NewItem;
++Count;
} // end if
} // end QueueInsert
void queueClass::QueueDelete(bool& Success)
{
Success = bool(!QueueIsEmpty());
if (Success)
{ // queue is not empty; remove front
Front = (Front+1) % MAX_QUEUE;
--Count;
} // end if
} // end QueueDelete
void queueClass::QueueDelete(queueItemType& QueueFront,
bool& Success)
{
Success = bool(!QueueIsEmpty());
if (Success)
{ // queue is not empty; retrieve and remove front
QueueFront = Items[Front];
Front = (Front+1) % MAX_QUEUE;
--Count;
} // end if
} // end QueueDelete
void queueClass::GetQueueFront(queueItemType& QueueFront,
bool& Success) const
{
Success = bool(!QueueIsEmpty());
if (Success)
// queue is not empty; retrieve front
QueueFront = Items[Front];
} // end GetQueueFront
// End of implementation file