![]() |
VOOZH | about |
Doubly Linked List implementation of deque allows constant-time insertion and deletion at both ends. We only need to maintain pointers or references to both the ends, front and rear.
The following four basic operations are typically performed on a deque:
Additionally, the following operations are also supported:
All operations on a deque,take O(1) time and O(1) extra space. Only the erase() operation takes O(n) time, since it removes all elements from the deque.
Insertion at Front :
Insertion at Rear :
Deletion from Front end :
Deletion from Rear end :
Rear: 10 New Rear: 5 Front: 15 Size: 2 New Front: 5