def test_peek(): s = MyStack() s.push(1) s.push(2) assert 2 == s.peek() s.push(3) assert 3 == s.peek() s.pop() assert 2 == s.peek()
class StackMin: def __init__(self): self.sMin = MyStack() def push(self,data): if data < self.min(): self.sMin.push(data) self.push(data) def pop(self): val = self.pop() if val == self.sMin.min(): self.sMin.pop() return val def min(self): return self.sMin.peek()