Stacks & Queues


Select all that apply
Answer & solution
Answer: B: 20, 20, 10, 10, 20 (no official key was published)
Step through it (12 steps)
After the first two pushes, the stack from bottom to top is [10, 20], so the first pop yields 20. Pushing 10 then 20 leaves [10, 10, 20]; the next three pops yield 20, 10, 10 and empty the stack. The final push/pop yields 20. Concatenating these five outputs gives 20, 20, 10, 10, 20. No pop is attempted on an empty stack. The result follows last-in-first-out order, not the chronological order of pushes as a queue would use.