Course contentsShow
← Computer Science
Lesson 396 of 2,8729. Stacks and QueuesFree lesson

Deque ADT Operations

Defining the abstract data type for deques with operations like addFront, addRear, removeFront, and removeRear.

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 deque
  • addRear(item) – Insert an element at the rear of the deque

Remove Operations

  • removeFront() – Remove and return the element from the front
  • removeRear() – Remove and return the element from the rear

Query Operations

  • getFront() or peekFront() – View the front element without removing it
  • getRear() or peekRear() – View the rear element without removing it
  • isEmpty() – Check if the deque contains no elements
  • size() – 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.