// Chap 7, pp 319 - 321
// Rename this file as QueueA.cpp
// ********************************************************
// Implementation file QueueA.cpp for the ADT queue.
// Circular array-based implementation.
// The array has indexes to the front and rear of the
// queue. A counter tracks the number of items currently
// in the queue.
// ********************************************************
#include "QueueA.h" // header file
// constructors and destructor:
queueClass::queueClass():
Front(0), Rear(MAX_QUEUE-1), Count(0)
{
} // end default constructor
queueClass::queueClass(const queueClass& Q):
Front(Q.Front), Rear(Q.Rear), Count(Q.Count)
{ for (int Index = 0; Index < Q.Count; ++Index)
Items[Index] = Q.Items[Index];
} // end copy constructor
queueClass::~queueClass()
{
} // end destructor
boolean queueClass::QueueIsEmpty()
{
return boolean(Count == 0);
}
void queueClass::QueueAdd(queueItemType NewItem,
boolean& Success)
{
Success = boolean(Count < MAX_QUEUE);
if (Success)
{ // queue is not full; insert item
Rear = (Rear+1) % MAX_QUEUE;
Items[Rear] = NewItem;
++Count;
} // end if
} // end QueueAdd
void queueClass::QueueRemove(boolean& Success)
{
Success = boolean(!QueueIsEmpty());
if (Success)
{ // queue is not empty; remove front
Front = (Front+1) % MAX_QUEUE;
--Count;
} // end if
} // end QueueRemove
void queueClass::GetQueueFront(queueItemType& QueueFront,
boolean& Success)
{
Success = boolean(!QueueIsEmpty());
if (Success)
// queue is not empty; retrieve front
QueueFront = Items[Front];
} // end GetQueueFront
// End of implementation file.
               (
geocities.com/siliconvalley/program/2864/ds)                   (
geocities.com/siliconvalley/program/2864)                   (
geocities.com/siliconvalley/program)                   (
geocities.com/siliconvalley)