ProgrammingHardAccenture · TCS · Infosys

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 59
enqueue 43
enqueue 60
dequeue
enqueue 11
enqueue 74
dequeue
dequeue
enqueue 57
enqueue 92
  1. A. 11, 74, 57
  2. B. 59, 43, 57, 92
  3. C. 92, 57, 74, 11
  4. D. 11, 74, 57, 92

Correct answer: D. 11, 74, 57, 92

A queue is FIFO: dequeue always removes the front (oldest) element. Tracing the sequence gives front-to-back [11, 74, 57, 92]. Treating it like a stack (removing the most recent instead) gives the trap [59, 43, 57, 92]; reading it back-to-front gives [92, 57, 74, 11].

More Pseudocode and Code Tracing questions

Exams that ask this topic