|
-
Apr 15th, 2002, 01:13 AM
#1
Thread Starter
Addicted Member
Queue class check
Here is a queue class that I need someone to check and correct anything wrong since I've got really bored.
I'm using a vacant location to check if queue is empty or full ,but it is not working.
enum Error_code{success,overflow,underflow};
const int maxqueue= 10;
typedef char Queue_entry;
class Queue{
public:
Queue();
bool empty()const;
bool full()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];
};
Queue::Queue()
{
front=0;
rear=maxqueue -1;
}
Error_code Queue::append (const Queue_entry &item)
{
//if there is space in the queue,item will be added at the end, otherwise an error_code of overflow is returned
if ((rear+1)%max+1==front
return overflow;
else
{rear=((rear+1)==max)?0:rear+1
entry[rear]=item;
return successs;
}
Error_code Queue::serve()
{
//if the queue is not empty, the 1st element is removed,otherwise an error_code of overflow is returned
front=((front+1)==max)?0:front+1
if (rear+1)%max==front
return overflow;
return success;
}
Error_code Queue::retrieve (Queue_entry &item)const
{
if ((rear+1)%max==front)
return underflow;
else
{item=entr[front];
return success;}
}
bool Queue::empty() const
{
if ((rear+1)%maxqueue ==front);
return true ; //empty queue
return false; //not empty
}
bool Queue::full() const
{
((rear+1)%maxqueue +1==front);
return true ; //full queue
return false; //not full
}
Last edited by nad_scorp; Apr 15th, 2002 at 02:17 PM.
Me "Talented Idiot" by Gtarawneh "He said he's sorry
Inconsequential is Incommunicable
The first impression we have
Is not always the real one
My reality is not always your
so my friend....Is life that simple?
It is called "Israeli occupation forces"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|