Is this supposed to be C, not C++? I question this because of int isempty(queue &q) -- the parameter looks like a c++ reference.
Is that supposed to be circular queue where the front and back variables wrap around to 0 then the buffer items is filled up? If yes or no you need to add code to the join() function to wrap the front variable when it reached MAX, or not allow any more items in the queue when (front+1) > rear.
You need to firm up your understanding of the front and back variables.
front: This is where the next item will be inserted into the queue. When an item is inserted (see join function) this is the variable that should get incremented.
rear: This is where the next item will be removed from the queue. When an item is removed from the queue (see leave function) this is the variable that will be incremented.
You need checks in join() that front+1 does not exceed rear. And you need checks in leave() that rear+1 does not exceed front.
Last edited by Ancient Dragon; Mar 27th, 2009 at 5:04 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 4835
Solved Threads: 1778
Still Learning
Offline 17,874 posts
since Aug 2005