ProgrammingVery hardWipro · TCS NQT 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 47
push 50
pop
push 47
push 19
push 28
push 10
push 93
  1. A. 47, 47, 19, 28, 10
  2. B. 47, 47, 19, 28, 10, 93
  3. C. 93, 10, 28, 19, 47, 47
  4. D. 50, 47, 19, 28, 10, 93

Correct answer: B. 47, 47, 19, 28, 10, 93

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

More Pseudocode and Code Tracing questions

Exams that ask this topic