Type of item stored inside the deque.
Retrieves the item at the provided position.
An index of -1 returns the tail item, 0 returns the head, and any
non-integer input is truncated toward zero.
Requested position inside the deque.
The referenced item or null when the position is out of range.
Removes and returns the item at the tail of the deque.
The removed item, or null if the deque is empty.
Appends items to the tail of the deque.
Items to append, in the order they should appear.
The updated deque length.
Removes and returns the item at the head of the deque.
The removed item, or null if the deque is empty.
Inserts items at the head of the deque.
Items to insert, where the first argument becomes the new head.
The updated deque length.
Represents a double-ended queue (deque) with amortized O(1) insertion and removal at both ends. The implementation stores items inside a sparse index map so the head and tail can grow independently without costly array shifts.
Example