303 views
1 votes
1 votes
In implementation of queue using circular array

if n=4

then actually oly 3 elements are filled?

2 Answers

Best answer
1 votes
1 votes
You can fill all the 4 slots but then at some point, it becomes possible for front and rear to point the same slot in the array which is an overflow/underflow condition and leads to confusion whether the queue is empty or full.
That is why we only use (n-1) slots to implement a queue using an array of size n.
selected by
2 votes
2 votes

yes, it is because to differentiate between Empty-Queue and Full-Queue conditions. Though we can use nth cell also to store data but in that case we need to take one counter variable which will how many elements are currently there in C-Queue.

No related questions found