Stack operations: push and pop
A stack has two main actions:
- **push*: put an item on top.
- **pop*: take the top item off.
push(1) -> [1]
push(2) -> [1][2]
pop() -> returns 2, leaves [1]
Stacks power things like the "back" button in a browser, undo history in editors, and function calls in a program.
Queue operations: enqueue and dequeue
A queue has two ends:
- **enqueue*: add at the back.
- **dequeue*: remove from the front.
enqueue(1) -> [1]
enqueue(2) -> [1][2]
dequeue() -> returns 1, leaves [2]
Queues model real waiting lines: print jobs, task lists, and how your computer handles requests in order.