ProgrammingHardInfosys · Capgemini 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 90
dequeue
enqueue 2
dequeue
enqueue 89
enqueue 62
enqueue 79
dequeue
dequeue
enqueue 80
  1. A. 89, 80
  2. B. 79, 80
  3. C. 80, 79
  4. D. 79

Correct answer: B. 79, 80

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

More Pseudocode and Code Tracing questions

Exams that ask this topic