Machine-translated by Google. Questions are authored in English.
Top

Discussion

In an array-based implementation of a circular queue, overflow occurs when

  • A.rear == front
  • B.rear == size - 1
  • C.front == -1
  • D.(rear + 1) % size == front

Answer: D

Overflow occurs when (rear + 1) % size == front.

In the usual array implementation, one slot is kept empty so that a full queue can be told apart from an empty one. The queue is full when advancing rear by one position, wrapping round with the modulus, would land on front.

\[ (rear + 1) \bmod size = front \Rightarrow \text{full} \]

rear == front is the test for an empty queue in this scheme. rear == size - 1 is the overflow test for a linear queue; in a circular queue there may still be free slots at the start of the array. front == -1 is how some implementations mark an empty queue, not a full one.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.