Difficulty with Circular Queue?

See below. The following are functions I am to implement for a project. The prototypes and what not are all given in a testing function, along with a status checker. I was provided the pseudo code that follows each function, and I believe I have followed it exactly. However, I still get errors.

In particular, the function cannot tell if it is in the overflow or full states, and also cannot retrieve data. Please help! I don't want to use array notation, I'd prefer to stick with pointers.

status putQueue (int item) {

if (current == FULL || current == OVERFLOW) {
// the queue is currently FULL or OVERFLOW
current = OVERFLOW;
}

else {
*tail = item;
tail++;

if (!tail) {
*tail = queue[0];

if (tail == head)
current = FULL;

else
current = PENDING;
}

current = PENDING;

/* pseudo code:
* put "item" to the location where "tail" points to;
* make "tail" increment (to point to the next location);
* check whether the incremented "tail" is beyond the queue?
* if yes, make "tail" point to the beginning of the queue;
* check whether the incremented "tail" is equal to "head"?
* if yes, it means the queue is FULL now, so change the status of the queue to FULL;
* if no, it means the queue is PENDING now, so put the status of the queue to PENDING;
*/

}
return current;
}

/** getQueue ********************************************************************
* @params - none
* @return: int
* Returns integer item from the queue. Status is updated
* but not returned. Returns 0 if no items available
*********************************************************************************/
int getQueue (void) {

int iValue;

if (current == EMPTY || current == UNDERFLOW) {
current = UNDERFLOW;
return 0;
}
else {
iValue = *head;
head++;

if (!head) {
*head = queue[0];

if (head == tail)
current = EMPTY;

else
current = PENDING;
}
}
return iValue;
}
/* pseudo code:
* check whether the queue is currently EMPTY or UNDERFLOW?
* if yes, set the status of the queue to UNDERFLOW and return 0;
* if no, do the following:
* retrieve the value (called "iValue" hereafter) from the location pointed by "head";
* make "head" increment (to point to the next location);
* check whether the incremented "head" is beyond the queue?
* if yes, make "head" point to the beginning of the queue;
* check whether the incremented "head" is equal to "tail"?
* if yes, it means the queue is EMPTY now, so change the status of the queue to EMPTY;
* if no, it means the queue is PENDING, so put the status of the queue to PENDING;
* return the retrieved value (ie, "iValue");
*/
Topic archived. No new replies allowed.