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"
Apr 15th, 2002, 01:42 PM
#2
Is this a school assignment? If you actually need this, you're better off using an STL queue template.
All the buzzt
CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Apr 15th, 2002, 02:09 PM
#3
Thread Starter
Addicted Member
yes it is
and I should not use STL but build the class from scratch and as u see I'm facing some little problems.
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"
Apr 15th, 2002, 02:39 PM
#4
I'm very confused by your start/end usage. I'd use a back-linked list (single-linked, but used from back to end)
(attached)
Attached Files
All the buzzt
CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Apr 15th, 2002, 03:43 PM
#5
Thread Starter
Addicted Member
never mind these start/close stuff were done on the forum
now I'm in the mood and it seems it is gonna work .As soon as I finish it I'll send it for anyone who needs it.
thanx
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