Stacks and Queues
LIFO stacks, FIFO queues, and everyday uses (undo, BFS).
What you will learn
- Implement stack with list append/pop
- Use collections.deque for queue
- Name real-world uses
python
from collections import deque
stack = []
stack.append("a")
stack.append("b")
print(stack.pop())
queue = deque()
queue.append("first")
queue.append("second")
print(queue.popleft())Try it yourself
Use a stack to check if a string of parentheses is balanced.
