Peek
Read the top item without removing it.
Decision · step 5 of 10Stack: Push, pop, peek
pop returns 9: the most recently pushed item leaves first.
What you will see
The top item is emphasized; nothing moves.
Cost
| Best | O(1) |
|---|---|
| Average | O(1) |
| Worst | O(1) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, try operations in any order.
Screen readers: Items announce position from the top or front and value; each step announces the operation and the new top or front.
Reduced motion: Items appear or disappear in place with a crossfade instead of sliding in or out.