Codele / Data structures
Queues
A line at a shop is fair: people join at the back and are served from the front. A queue in code works the same way.
- A queue is a line: join at the back, leave from the front.
- The oldest thing leaves first: first in, first out. A stack is the opposite: last in, first out.
- Joining is often called enqueue and leaving dequeue.
- Print queues, customer helplines and waiting lists all use queues.
- Taking from the front of a plain array is slow, because everyone behind must shift one place, as in the arrays lesson. Queue types avoid that.
Loading the playable lesson…