Algorithm
Doubly Ended Queue (Deque) Algorithm:
- Initialize the deque with a fixed size or dynamic structure.
- Operations on the deque:
- Insert at Front:
- Check if the deque is full.
- If not full, insert the element at the front.
- Insert at Rear:
- Check if the deque is full.
- If not full, insert the element at the rear.
- Delete from Front:
- Check if the deque is empty.
- If not empty, remove the element from the front.
- Delete from Rear:
- Check if the deque is empty.
- If not empty, remove the element from the rear.
- Peek Front: Retrieve the front element without removing it.
- Peek Rear: Retrieve the rear element without removing it.
- Insert at Front:
Example:

Fig. 1: Operations on a Doubly Ended Queue
Note: Deques are versatile data structures that can be used as both stacks and queues.