Deque
Deque stands for a “double-ended queue”. It is an Abstract Data Type that generalizes a Queue, for which elements can be added to or removed from either the front or back.
→ Think the power of Stacks and Stacks and Queues combined
Implementation
The built-in deque implementation is actually a little complicated, I don’t understand it yet.
Think of it like a Circular buffer of objects
The STL use a circular buffer of Pointers.
Python collections.deque
We use the deque
library to implement Stacks and Queues in Python. Check out documentation for functions.
→ Deque is preferred over list for the time complexity advantages on append and pop operations.
C++ Deque
Dynamic array in C++ that extends upon the C++ Vector by also including push_front
and pop_front
.
Check reference.