Master LIFO and FIFO processing models
Section 4 of 8
While stacks are about efficiency, queues are about Fairness. If you arrived first, you get served first.
Think of a line at a ticket counter. People enter at the **REAR** and leave from the **FRONT**. This order ensures that data is processed exactly as it arrives.
Where we DEQUEUE (exit). Like the person currently talking to the teller.
Where we ENQUEUE (entry). Like the person just joining the line.
FIFO Simulation
Queues are essential when the order of arrival determines the quality of service (e.g., bank lines, print jobs).
Queues let systems with different speeds communicate. A fast producer can "buffer" data into a queue for a slow consumer.
Queues power CPU task scheduling, ensuring every program gets its fair share of processing time.