Suppose we perform the following operations on a Stack: (push 1) (push 2) (push 3) (pop) (pop) (push 4) (pop) (pop)
What is the order of the items that come out?

  • A: 1, 2, 3, 4
  • B: 4, 3, 2, 1
  • C: 2, 3, 1, 4
  • D: 3, 2, 4, 1
  • E: 2, 3, 4, 1

    Answer: D

    push and pop both operate at the top of the stack only. If we use a list as the stack, with the top of stack at the left, the successive operations are:

    Contents    Page-10    Prev    Next    Page+10    Index