The values 4, 9 and 2 are added, in that order, to an empty stack and also to an empty queue. Two items are then removed from each. Which item is left in each structure?
- Stack: 2 was pushed last, so it is popped first, then 9. The item 4 is left.
- Queue: 4 joined first, so it leaves first, then 9. The item 2 is left.
Answer: The stack holds 4 and the queue holds 2.