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 isempty;
};
Queue:: Queue( )
{
rear = maxqueue− 1;
front = 0;
isempty = true;
}
bool Queue:: empty( ) const
{
return isempty;
}
Error_code Queue :: append(const Queue_entry &item)
{
if (!empty( )&&(rear +1) % maxqueue == front)
return overflow;
isempty = false;
rear = ((rear ‚+1) == maxqueue) ? 0 : (rear ‚+1) ;
entry[ rear ] = item;
return success;
}
Error_code Queue :: serve( )
{
if (empty( ))
return underflow ;
if (rear == front)
isempty = true;
front = ((front ‚+1) == maxqueue) ? 0 : (front ‚+1) ;
return success;
}
Error_code Queue :: retrieve(Queue_entry&item) const
{
if (empty( ))
return underflow ;
item = entry[front];
return success;
}