問題文
An ArrayDeque is used as a stack. Which pair of operations pushes an element and then removes the most recently pushed element?
選択肢
- add followed by remove, because the single argument forms of those two methods are defined to work on the same end of the deque as push and pop do.
- push followed by pop, both of which operate on the head of the deque, so the element added last is the one that leaves.
- offer followed by poll, both of which operate on the head of the deque and therefore produce last in first out behavior for the caller.
- push followed by poll, which work on opposite ends, and so an element that arrived first is one that leaves first.