1, Part 7)
What is a Deque?
A Double Ended Queue allows insertion and deletion from both front and rear ends.
Can function as both Stack and Queue.
States of a Deque
Condition | FRONT | REAR
----------------------------------|------------|-------------
Deque is Empty | -1 | -1
Deque is Full |0 | SIZE - 1
Only One Element | FRONT = REAR
Number of Elements | REAR - FRONT + 1
Operations in Deque
Operation | Description
----------|--------------------------------------
PUSH | Enqueue at the FRONT
POP | Dequeue from the FRONT
INJECT | Enqueue at the REAR
EJECT | Dequeue from the REAR
DISPLAY | Show all elements in the Deque
PUSH Algorithm (Insert at FRONT)
if FRONT == 0 and REAR == SIZE-1:
Deque is FULL
elif FRONT == -1 and REAR == -1:
FRONT = REAR = 0
A[FRONT] = ITEM