Deque ADT Operations
What you'll learn: You'll discover the complete set of operations that define the deque abstract data type and make it uniquely flexible.
What Makes Deque Operations Special?
You've learned that a deque (double-ended queue) allows access from both ends. Now let's formalize its operations as an ADT. Unlike a stack (one-end access) or queue (strict FIFO), the deque gives you four insertion and removal operations instead of two.
Core Deque Operations
Insert Operations
addFront(item)– Insert an element at the front of the dequeaddRear(item)– Insert an element at the rear of the deque
Remove Operations
removeFront()– Remove and return the element from the frontremoveRear()– Remove and return the element from the rear
Query Operations
getFront()orpeekFront()– View the front element without removing itgetRear()orpeekRear()– View the rear element without removing itisEmpty()– Check if the deque contains no elementssize()– Return the number of elements
The Power of Flexibility
Think of a deque like a line of people where someone can join at either the front or back, and people can leave from either end too. This makes it powerful: you can simulate a stack (use only one end), a queue (add at one end, remove from the other), or use both ends creatively for algorithms that need flexibility.
Key Takeaway: The deque ADT defines eight operations (four for insertion/removal at both ends, plus standard queries), making it the most flexible linear collection structure you've encountered so far.