A plain FIFO queue · Sequential teaching example

Arrival order
becomes removal order.

Add at the back. Remove from the front.

Front
ABC
Back

Start state: A arrived before B; B arrived before C.

Toy queue · No concurrency or performance claim1 / 5

Adding one item

D joins the back; A stays first.

Before

Front
ABC
Back
enqueue(D)

Append one item; keep the existing order.

Front
ABCD
Back
Toy queue · Dashed coral token is the new item2 / 5

Removing two items, one operation at a time

A leaves first.
Then B.

dequeue() → ARemaining: [B, C, D]
dequeue() → BRemaining: [C, D]
Front
CD
Back
Toy queue · Returned items follow arrival order3 / 5

Adding again, then draining the queue

E waits behind C and D.

enqueue(E)

Start from [C, D], then append E.

Front
CDE
Back
Three removals returnCDE

After those three removals, no items remain.

Toy queue · This walkthrough uses sequential operations4 / 5

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.