Reach for a queue when the order things arrive in is the order they must be handled. In practice that shows up as four signals. Spot one, and a queue is almost always part of the answer.
Print jobs, requests to a web server, orders in a shop, messages between two programs: each must be handled fairly, oldest first. A queue also absorbs bursts — when work arrives faster than it can be done, it waits in line instead of being lost or reordered.
Members only · free account
The rest of this lesson, with 6 more sections, 3 drawings, 2 dry-run simulators and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson