Stack
A last-in-first-out (LIFO) structure where the last item in comes out first. Insertion and removal happen only at one end (the top), and it's the backbone of the call stack, undo, bracket matching, and DFS.
01Stack
Explore How It WorksStarting the stack. A last-in-first-out (LIFO) structure where you push and pop only at one end (top).
push(10) · Place 10 on top.
push(24) · Place 24 on top.
push(37) · Place 37 on top.
peek() · Inspect the top value 37 without removing it.
pop() · Mark the top 37 for removal.
37 is popped. top moves down one to 24.
pop() · This time mark the top 24 for removal.
24 is popped. The last value in comes out first — that's LIFO.
02 Understand It Simply
For EveryoneValues go in and come out at the same end, so the last one in is the first one out.
You add and remove only at one end (the top).
The most recently added item comes out first (last-in-first-out, LIFO).
- –Undo (Ctrl+Z)
- –browser back button
- –bracket-pair checking
03 Python Implementation
A clean, readable reference implementation of the core logic of Stack.
04 Frequently Asked Questions
FAQWhat is Stack?+
A last-in-first-out (LIFO) structure where the last item in comes out first. Insertion and removal happen only at one end (the top), and it's the backbone of the call stack, undo, bracket matching, and DFS.
What is the time complexity of Stack?+
The time complexity of Stack is O(1) push/pop. Follow the step-by-step visualization to see exactly why.
Where is Stack used?+
Undo (Ctrl+Z), browser back button, bracket-pair checking.
What's a simple analogy for Stack?+
Values go in and come out at the same end, so the last one in is the first one out.
