📚 Stack LIFO
Last In, First Out — like a stack of plates. Push adds to top, pop removes from top.
Visual
[ empty stack ]Push items to see them stack up ↑
▼ BOTTOM
Operations
Push an item to begin.
0
Size
0
Ops done
Operation Log
Operations appear here…
🚶 Queue FIFO
First In, First Out — like a real queue. Enqueue adds to rear, dequeue removes from front.
Visual
FRONT →← REAR
[ empty queue ]
Operations
Enqueue an item to begin.
0
Size
0
Ops done
Quick Reference
Stack (LIFO):
push(x) → O(1)   pop() → O(1)
peek() → O(1)  is_empty() → O(1)

Queue (FIFO):
enqueue(x) → O(1)  dequeue() → O(1)
front() → O(1)   is_empty() → O(1)
Difficulty
🟢 Beginner
🟡 Intermediate
🔴 Advanced
🎲 All
0 XP
0 / 0
Loading questions…
0 correct    ❌ 0 wrong
📊 Stack vs Queue — Head-to-Head Comparison
📚 Stack (LIFO)
OrderLast In, First Out
Addpush() — top
Removepop() — top
Peekpeek() / top()
Pythonlist.append/pop
SpaceO(n)
Time opsO(1) all
🚶 Queue (FIFO)
OrderFirst In, First Out
Addenqueue() — rear
Removedequeue() — front
Peekfront()
Pythoncollections.deque
SpaceO(n)
Time opsO(1) all
💻 Python Code Examples
# Stack using list stack = [] stack.append(10) # push stack.append(20) stack.append(30) print(stack.pop()) # 30 — LIFO print(stack[-1]) # peek → 20
# Queue using deque from collections import deque q = deque() q.append(10) # enqueue (rear) q.append(20) q.append(30) print(q.popleft()) # 10 — FIFO print(q[0]) # front → 20
🌍 Real-World Use Cases
🌐
Browser Back Button
Stack — each page visited is pushed; back button pops
🖨️
Print Queue
Queue — first document sent is printed first (FIFO)
↩️
Undo Feature
Stack — each action pushed; Ctrl+Z pops last action
🖥️
CPU Scheduling
Queue — processes handled in order they arrive (FIFO)
📞
Call Center
Queue — first caller on hold is first to be answered
🧠
DFS Algorithm
Stack — depth-first search explores deepest path first
🗺️
BFS Algorithm
Queue — breadth-first explores level by level outward
Bracket Checker
Stack — push opening, pop and match when closing found