A queue models the most natural form of fairness: whoever arrives first is served first. Elements enter from one end (the rear) and leave from the other end (the front). This FIFO discipline makes queues the natural choice for any system where order of arrival determines order of service — operating system schedulers, network packet buffers, printer spoolers, and breadth-first graph traversal all rely on queues at their core.
A queue is a linear data structure with a strict two-end access rule: elements are always added at the REAR (also called tail or back) and always removed from the FRONT (also called head). No element in the middle can be accessed directly. The first element enqueued is the first to be dequeued — FIFO.
The element 12 arrived first — it sits at the FRONT and will leave first. Element 48 arrived last — it sits at the REAR and will be the last to leave. Unlike a stack, you cannot access any element other than the one at the FRONT.
A queue has four primary operations. All are O(1) when implemented correctly.
| Operation | Simple Queue | Circular Queue | Deque | Priority Queue (Heap) |
|---|---|---|---|---|
| Enqueue / AddRear | O(1) | O(1) | O(1) | O(log n) |
| Dequeue / RemoveFront | O(1) | O(1) | O(1) | O(log n) |
| AddFront | N/A | N/A | O(1) | N/A |
| RemoveRear | N/A | N/A | O(1) | N/A |
| Peek / Front | O(1) | O(1) | O(1) | O(1) |
| Search | O(n) | O(n) | O(n) | O(n) |
| Space usage | Wastes freed slots | Reuses all slots | Dynamic | Compact array |
The Linear DS Quest contains three dedicated tabs for queue types. Switch between them using the tabs inside the game. The Queue tab shows simple FIFO enqueue and dequeue. The Deque tab demonstrates insertions and deletions at both ends. The Circular Queue tab shows the wrap-around behaviour with a visual ring of 8 slots.