A plain FIFO queue · Sequential teaching example
Arrival order
becomes removal order.
Add at the back. Remove from the front.
Front
ABC
BackStart state: A arrived before B; B arrived before C.
Adding one item
D joins the back; A stays first.
Before
Front
ABC
Backenqueue(D)Append one item; keep the existing order.
Front
ABCD
BackRemoving two items, one operation at a time
A leaves first.
Then B.
dequeue() → ARemaining: [B, C, D]dequeue() → BRemaining: [C, D]Front
CD
BackAdding again, then draining the queue
E waits behind C and D.
enqueue(E)Start from [C, D], then append E.
Front
CDE
BackThree removals returnCDE
After those three removals, no items remain.
The boundary of this toy API
Empty is a state.
Check what the API reports.
EMPTY
Our toy dequeue() reports EMPTY and returns no item.
Specific to this example
Another queue API may choose a different empty-queue behavior.
Check its documented contract.