ProgrammingHardTCS NQT · Accenture pattern

What is the final content of the stack (bottom to top, left to right) after this sequence of operations on an initially empty stack?

What is the final content of the stack (bottom to top, left to right) after this sequence of operations on an initially empty stack?
push 90
push 23
push 26
push 63
pop
pop
push 71
pop
  1. A. 90, 23, 71
  2. B. 90, 23
  3. C. 23, 90
  4. D. 63, 71

Correct answer: B. 90, 23

Tracing push/pop on an empty stack in order gives, bottom-to-top, [90, 23]. Reading top-to-bottom instead gives the reversed trap [23, 90]; mistakenly treating "pop" as removing the front (as in a queue) gives [63, 71].

More Pseudocode and Code Tracing questions

Exams that ask this topic