Stacks and Queues
Stack (LIFO)
All operations O(1). Use for: DFS, backtracking, bracket matching, undo/redo, recursion-to-iteration.
Array-Based Stack
class ArrayStack:
def __init__(self):
self._items = []
def push(self, item): self._items.append(item)
def pop(self):
if not self._items: raise IndexError("Pop from empty stack")
return self._items.pop()
def peek(self):
if not self._items: raise IndexError("Peek from empty sta
[Description truncada. Veja o README completo no GitHub.]