Master LIFO and FIFO processing models
Section 5 of 8
Simple queues waste memory and lack priority. Modern software needs Circular Queues, Priory Queues, and Deques.
In a simple array-based queue, once the tail reaches the end, you can't insert back at the beginning even if space is freed. A **Circular Queue** solves this by connecting the end back to the start.
next_index = (current + 1) % capacityThis simple modulo operation creates an infinite loop effect, recycling memory perfectly.
Circular Queue simulation
Here, the "Fairness" rule changes. Every element has a **priority**. Highest priority items jump the line. Essential for hospital ERs and system interrupts.
The Swiss Army Knife of linear structures. You can Enqueue and Dequeue from **BOTH** ends. It can act as a Stack AND a Queue simultaneously.
| Type | Primary Advantage | Memory Use |
|---|---|---|
| Linear Queue | Simple to implement | Wasteful (Dead space) |
| Circular Queue | Memory Recycling | Optimized |
| Priority Queue | Importance Based | Moderate (Heap based) |
| Deque | Maximum Flexibility | Moderate |