LOGBOOK

HELP

Quiz Entry - updated: 2026.09.29

Starting from an empty deque, what do addFirst(3), addFirst(5), removeFirst(), addLast(7), removeFirst(), removeLast(), removeFirst() return?

removeFirst() → 5, removeFirst() → 3, removeLast() → 7, and the final removeFirst() → null on the empty deque.

Operation Returns Deque (front … rear)
addFirst(3) — (3)
addFirst(5) — (5, 3)
removeFirst() 5 (3)
addLast(7) — (3, 7)
removeFirst() 3 (7)
removeLast() 7 ()
removeFirst() null ()

The step that trips people up is addFirst(5) after addFirst(3): adding at the front pushes the 3 back, so the 5 becomes the new front. The first two operations together therefore behave like a stack (5 comes out before 3). Later, addLast(7) joins at the rear, and after removeFirst() takes the 3, the 7 is both first and last, so removeLast() returns it.

From Quiz: ADS / Linear Data Structures: Lists, Stacks, Queues, Deques, Iterators | Updated: Sep 29, 2026