in Programming in C
1,771 views
0 votes
0 votes
#DS
I have this confusion in concluding the overflow condition of a circular Queue i.e. when the circular queue will be considered full.

As per the text i have, it says a circular queue is full when:
Front=0 and Rear=MAX-1 ; which seems quite straight forward.
eg: The queue [10,5,8,6,4] where MAX=5, Front=0 and Rear=4 looks full. But if we carry a single Dequeue operation and a single Enqueue operation for inserting 12, we will see:
[12,5,8,6,4] where MAX=5, Front=1, Rear=0
In the above situation, Front isn't 0 and Rear isn't Max-1, although still the queue is quite full. So my question is shouldn't the overflow condition of a circular Queue be:
if((Front==0 && Rear==MAX-1) || (Rear==Front-1))

???
in Programming in C
1.8k views

1 comment

if front = (rear+1)%MAX , then we can tell queue is full.
0
0

1 Answer

0 votes
0 votes
Best answer
For circular queue condition for checking if the queue is full is ((rear == SIZE-1 && front == 0) || (rear == front-1)).
selected by