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:
- initial: stack = ()
- (push 1) stack = (1)
- (push 2) stack = (2 1)
- (push 3) stack = (3 2 1)
- (pop) stack = (2 1), 3 is produced
- (pop) stack = (1), 2 is produced
- (push 4) stack = (4 1)
- (pop) stack = (1), 4 is produced
- (pop) stack = (), 1 is produced
Contents
Page-10
Prev
Next
Page+10
Index