In the game, this was a ramen shopPlay “Plates & the Ramen Line”
| In the game | In real IT |
|---|---|
| Bowl | Data |
| Bowl pile (take from the top) | Stack (LIFO) |
| Waiting line (out from the front) | Queue (FIFO) |
| Stack / Take top | push / pop |
| Line up / Take front | enqueue / dequeue |
Stack = last in, first out (LIFO)
Like a pile of plates, you add to the top and take from the top. Putting in is called push and taking out is called pop. Ctrl+Z (undo) and the browser’s “Back” button pile your history of actions on a stack and take them off newest first.
Queue = first in, first out (FIFO)
Like a checkout line, you join at the back and leave from the front. Putting in is called enqueue and taking out is called dequeue. A printer’s print queue and the requests waiting to be processed by a server are queues.
| Stack | Queue | |
|---|---|---|
| Order out | Newest first | Oldest first |
| Abbreviation | LIFO | FIFO |
| Put in / take out | push / pop | enqueue / dequeue |
| Everyday examples | A pile of plates, undo | A checkout line, print queue |
How the FE exam asks it
A common question: “Push 1, 2, 3 onto an empty stack in that order, then pop twice. What remains?” With a stack, 3 and 2 come out and 1 remains. Do the same with a queue, and 1 and 2 come out and 3 remains.
- A stack is last in, first out (LIFO): push and pop
- A queue is first in, first out (FIFO): enqueue and dequeue
- “Undo” is a stack; a “line of tasks waiting” is a queue