Arrange the steps of insertion of an element in a circular queue in the correct order.
(A) Check if the queue is FULL
(B) Insert the element at the rear position
(C) Update the rear pointer
(D) If the rear is at the last index, then set it to 0.
Arrange the steps of insertion of an element in a circular queue in the correct order.
(A) Check if the queue is FULL
(B) Insert the element at the rear position
(C) Update the rear pointer
(D) If the rear is at the last index, then set it to 0.
Solution
(A) Check if the queue is FULL, because insertion is not possible if there is no free space.
(D) If the rear is at the last index, set it to 0, so the position wraps around to the start of the array.
(B) Insert the element at the rear position, which is now a valid index.
(C) Update the rear pointer so it records the new position of the last element.
Options 2 and 4: the element is inserted before the wrap-around check. If rear is at the last index, the element would be written outside the array.
Related questions:
2026: 19 May Shift 1
2025: 3 June Shift 2