deque

Deque: Double-ended queue is a versatile data structure

A deque is a double-ended queue. You could insert and delete items from both ends.

Operations supported on deque:

  • insertFront() : adds an item at front of the deque
  • insertLast(): adds an item at the rear of the deque
  • removeFront(): removes an item from front of the deque
  • removeLast(): removes an item from rear of the deque

It acts like a stack if you restrict only to the following operations: insertFront() and removeFront() or other equivalent right operations.

It acts like a queue if you restrict only to the following operations: insertFront() and removeLast() or the opposite pair.

So we can say deque provides a more versatile data structure than either stack or a queue. However it is not used often compared to stacks and queues in practice.

Application of deque:

You can effectively solve problems where items need to be added and or removed at both ends using deque.

Recommended Posts

Reference

Leave a Reply

avatar
  Subscribe  
Notify of