Source
1. The queue rule
A queue holds items in order. Enqueue adds an item at the back. Dequeue removes the item at the front.
The first item added is the first removed: first in, first out (FIFO). Removing the most recently added item instead would follow a stack’s last-in, first-out rule.
2. Follow the items
Start with A at the front, followed by B, then C at the back. Dequeue once, then enqueue D.
| Operation | Contents | Removed |
|---|---|---|
| Start | A, B, C | None |
| Dequeue | B, C | A |
| Enqueue D | B, C, D | None |
B is now at the front. D joined at the back without moving ahead of B or C.
Authored for this example. No university material or private uploads are used.