Deque
A queue where you can add and remove at both ends, the front and the rear. It can work as a stack and as a queue.
Example
With [A, B]: adding C at the front gives [C, A, B], and removing from the rear returns B.
Test yourself: Deque
Deques
A deque has ___ basic add and remove operations.
Add at the front, add at the rear, remove from the front and remove from the rear, each in O(1).
Deques
With [C, A, B], removing from the rear returns ___.
The rear is the right: B comes out and 2 remain, [C, A]. Removing from the front would have returned C.
Deques
Why does a deque use a doubly linked list and not a singly linked one?
In a singly linked list of 10,000 nodes, finding the second-to-last is 9,999 jumps. In a doubly linked one, the last points to the second-to-last: 1 step.
0/3
â–¶ Play