A queue is a First-In First-Out (FIFO) data structure. Elements are added at the rear (enqueue) and removed from the front (dequeue). A peek at the front element is called front(). All three operations are O(1) in a proper implementation using a circular buffer or doubly-ended linked list. Queues are the backbone of BFS traversal, task scheduling, and message passing systems.
Example: Watch enqueue, dequeue, and front operations on a live queue.
When to use this
→BFS (Breadth-First Search) — level-by-level graph / tree traversal
→Task scheduling — OS process queues, job queues in web servers
→Message passing — Kafka, RabbitMQ, SQS are all queues at their core
→Print spooler / buffering between producer and consumer