Order matters: last-in-first-out vs. first-in-first-out
A stack and a queue both hold a list of items, but they disagree about which one comes back out first.
A stack is last-in-first-out: like a stack of dishes, the last plate you put down is the first one you pick back up.
A queue is first-in-first-out: like a checkout line, the first person to join the line is the first one served.
- A stack: add to the top, remove from the top (LIFO).
- A queue: add to the back, remove from the front (FIFO).
- Same kind of list, different end you remove from.