TOPIC
FIFO and its variants: linear, circular, deque and priority.
WHY DID WE NEED QUEUES?
THE WALLStacks serve the NEWEST first — unfair and wrong for scheduling: the first print job, the first network packet, the first customer should go first.
THE IDEARestrict the other way: enqueue at the back, dequeue from the front — FIFO. Arrival order is preserved, both ends O(1).
Any queue at a counter: first come, first served. Printer spoolers, task schedulers and BFS all run on this.
A linear array with front and rear indices — and a wasteful flaw.
Indices wrap with % N, so freed slots are reused — nothing wasted.
Double-ended: insert and delete at both the front and the rear.
Serve by priority, not arrival — unsorted array vs binary heap.