Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bisect
- class Stack(list):
- def __init__(self, *args):
- super(Stack, self).__init__(*args)
- self._sorted = sorted(self)
- def push(self, value):
- self.append(value)
- bisect.insort(self._sorted, value)
- def pop(self):
- value = super(Stack, self).pop()
- self._sorted.remove(value)
- return value
- def peek(self):
- return self[-1] if self else None
- def get_max(self):
- return self._sorted[-1] if self else None
Advertisement
Add Comment
Please, Sign In to add comment