ProgrammingHardAccenture · TCS · Infosys

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 93
push 88
push 26
push 81
pop
push 87
pop
  1. A. 93, 88, 26
  2. B. 93, 88, 26, 87
  3. C. 26, 88, 93
  4. D. 26, 81, 87

Correct answer: A. 93, 88, 26

Tracing push/pop on an empty stack in order gives, bottom-to-top, [93, 88, 26]. Reading top-to-bottom instead gives the reversed trap [26, 88, 93]; mistakenly treating "pop" as removing the front (as in a queue) gives [26, 81, 87].

More Pseudocode and Code Tracing questions

Exams that ask this topic