The class definition for this queue implementation is as follows.
const int maxqueue=10;
class Queue{
Public:
Queue();
Bool empty()const;
Error_code serve();
Error_code append(const Queue_entry &item);
Error_code retrieve(Queue_entry&item)const;
Protected:
int front ,rear;
Queue_entry entry[maxqueue];
bool is_empty;
};
The method implementations follow.
Queue::Queue()
{
rear=-1;
front=0;
is_empty=true;
}
Bool Queue::empty()const
{
return is_empty;
}
Error_code Queue::append(const Queue_entry &item)
{
if(!empty()&&(rear+1)%maxqueue==front)return overflow;
is_ empty=false;
Rear=((rear+1)==maxqueue)?0:(rear+1);
Entry[rear]=item;
return success;
}
Error_code Queue;:retrieve(Queue_entry&item)const
{
if((empty())return underflow;
item=entry[front];
Return success;
}