Deque also known as double eneded queue, as name suggests is a special kind
of queue in which insertions and deletions can be done at the last as well
as at the beginning.
A link-list representation of deque is such that each node points to the next
node as well as the previous node. So that insertion and deletions take constant
time at both the beginning and the last.
Now, deque can be used to implement a stack and queue. One simply needs to
understand how deque can made to work as a stack or a queue.
The functions of deque to tweak them to work as stack and queue are list below.
Input : Stack : 1 2 3 Push(4) Output : Stack : 1 2 3 4 Input : Stack : 1 2 3 Pop() Output : Stack : 1 2
Input: Queue : 1 2 3 Enqueue(4) Output: Queue : 1 2 3 4 Input: Queue : 1 2 3 Dequeue() Output: Queue : 2 3
Stack: 7 8 Stack: 7 Queue: 12 13 Queue: 13 Size of Stack is 1 Size of Queue is 1
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Implement a stack using single queue
- How to implement stack using priority queue or heap?
- Stack and Queue in Python using queue Module
- Check if a queue can be sorted into another queue using a stack
- Implement Stack using Queues
- Implement a stack using singly linked list
- Design and Implement Special Stack Data Structure | Added Space Optimized Version
- Check if moves in a stack or queue are possible or not
- Difference between Stack and Queue Data Structures
- Level order traversal in spiral form | Using one stack and one queue
- deque::front() and deque::back() in C++ STL
- deque::clear() and deque::erase() in C++ STL
- deque::at() and deque::swap() in C++ STL
- Stack Permutations (Check if an array is stack permutation of other)
- Infix to Postfix using different Precedence Values for In-Stack and Out-Stack