Guest User

Untitled

a guest
Jan 13th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import bisect
  2.  
  3. class Stack(list):
  4.     def __init__(self, *args):
  5.         super(Stack, self).__init__(*args)
  6.         self._sorted = sorted(self)
  7.  
  8.     def push(self, value):
  9.         self.append(value)
  10.         bisect.insort(self._sorted, value)
  11.  
  12.     def pop(self):
  13.         value = super(Stack, self).pop()
  14.         self._sorted.remove(value)
  15.         return value
  16.  
  17.     def peek(self):
  18.         return self[-1] if self else None
  19.  
  20.     def get_max(self):
  21.         return self._sorted[-1] if self else None
Advertisement
Add Comment
Please, Sign In to add comment