🧮Queue (Data Structure)
Also known as Queue, FIFO, First In, First Out
A line where the first item in is the first one out. Join at the back.
Think of it like
Think of it like a line at a shop. The first person in line is the first one served.
Example
Emma and then Jack send pages to the office printer. The queue prints Emma's page first, because it arrived first.
Why it matters
Queues keep work fair and in order when it arrives faster than it can be done.
Definition
Example code
python
>>> from collections import deque
>>> q = deque()
>>> q.append("Emma")
>>> q.append("Jack")
>>> q.popleft()
'Emma'Common mistake
Key takeaways
- 1First in, first out. Like a line at a shop.
- 2Back in, front out. Enqueue and dequeue.
- 3Keeps order. Fair for waiting work.