UGC-NET Dec 2008 · Arrays & Matrix Representation

MCQ · 2 marks · Problem PROG-DSTR-0018

If $(rear==maxsize-1)$ $rear=0;$ else $rear=rear+1;$ is required in :
  1. A
    circular queue
  2. B
    linear queue
  3. C
    stack
  4. D
    deque

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionThe statement sends \(\text{rear}\) back to index 0 after the last slot \(\text{maxsize}-1\); it is the same as\[\text{rear}=(\text{rear}+1)\bmod\text{maxsize}.\]Wrapping around so that freed slots at the front are reused is exactly how a circular queue advances its rear.(B) A linear queue never wraps; it reports overflow at \(\text{maxsize}-1\) — incorrect.(C) A stack uses only a top index — incorrect.(D) A deque needs indices moving in both directions, not just this one rule — incorrect.Answer: A

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com