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
- 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
- Check if moves in a stack or queue are possible or not
- Difference between Stack and Queue Data Structures
- Design and Implement Special Stack Data Structure | Added Space Optimized Version
- 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
- Infix to Postfix using different Precedence Values for In-Stack and Out-Stack
- Stack Permutations (Check if an array is stack permutation of other)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.