ProgrammingHardCapgemini · Infosys pattern

What is the final content of the queue (front to back, left to right) after this sequence of operations on an initially empty queue?

What is the final content of the queue (front to back, left to right) after this sequence of operations on an initially empty queue?
enqueue 78
enqueue 13
dequeue
enqueue 32
dequeue
enqueue 45
enqueue 13
  1. A. 13, 45, 32
  2. B. 32, 45, 13
  3. C. 32, 45
  4. D. 78, 45, 13

Correct answer: B. 32, 45, 13

A queue is FIFO: dequeue always removes the front (oldest) element. Tracing the sequence gives front-to-back [32, 45, 13]. Treating it like a stack (removing the most recent instead) gives the trap [78, 45, 13]; reading it back-to-front gives [13, 45, 32].

More Pseudocode and Code Tracing questions

Exams that ask this topic