Queue
A linear data structure that follows the First-In-First-Out (FIFO) principle.
A queue is an abstract data type where elements are added at the back (enqueue) and removed from the front (dequeue). It mimics real-world waiting lines and is vital for asynchronous tasks, printer spooling, and breadth-first search algorithms.
graph LR
Center["Queue"]:::main
Rel_stack["stack"]:::related -.-> Center
click Rel_stack "/terms/stack"
Rel_array["array"]:::related -.-> Center
click Rel_array "/terms/array"
classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
linkStyle default stroke:#4b5563,stroke-width:2px;
🧠 Knowledge Check
1 / 1
🧒 Explain Like I'm 5
A queue is like a line at a grocery store. The first person to join the line is the first person to be served and leave. If you arrive late, you have to wait at the back for everyone in front of you to finish.
🤓 Expert Deep Dive
Priority queues use heaps to defy strict FIFO for urgent tasks. Circular queues (ring buffers) are used in high-performance networking and audio processing to avoid the O(n) cost of shifting elements after a dequeue.