Algorithm


Doubly Ended Queue (Deque) Algorithm:

  1. Initialize the deque with a fixed size or dynamic structure.
  2. Operations on the deque:
    1. Insert at Front:
      1. Check if the deque is full.
      2. If not full, insert the element at the front.
    2. Insert at Rear:
      1. Check if the deque is full.
      2. If not full, insert the element at the rear.
    3. Delete from Front:
      1. Check if the deque is empty.
      2. If not empty, remove the element from the front.
    4. Delete from Rear:
      1. Check if the deque is empty.
      2. If not empty, remove the element from the rear.
    5. Peek Front: Retrieve the front element without removing it.
    6. Peek Rear: Retrieve the rear element without removing it.

Example:

Doubly Ended Queue Example

Fig. 1: Operations on a Doubly Ended Queue

Note: Deques are versatile data structures that can be used as both stacks and queues.