Practice mode Data Structures

In a circular queue implemented with an array of size n, using front and rear indices with one slot always left empty, which condition means the queue is full?

Correct answer D. (rear + 1) % n == front

Explanation

Leaving one slot unused lets front == rear stand for an empty queue, so full must be distinguished differently: the queue is full when advancing rear by one, with wrap-around, would land on front. rear == n − 1 is the full test for a simple linear queue and ignores the free slots that wrap-around reclaims, which is the whole point of a circular queue.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.