Results 1 to 5 of 5

Thread: Queue class check

  1. #1

    Thread Starter
    Addicted Member nad_scorp's Avatar
    Join Date
    Feb 2001
    Location
    Inside XML
    Posts
    242

    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"

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  3. #3

    Thread Starter
    Addicted Member nad_scorp's Avatar
    Join Date
    Feb 2001
    Location
    Inside XML
    Posts
    242
    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"

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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 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.

  5. #5

    Thread Starter
    Addicted Member nad_scorp's Avatar
    Join Date
    Feb 2001
    Location
    Inside XML
    Posts
    242
    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
  •  



Click Here to Expand Forum to Full Width