Guest User

Untitled

a guest
Jan 13th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. class Stack:
  2.     def __init__(self):
  3.         self.items = []
  4.         self.current_max = None
  5.  
  6.     def push(self, item):
  7.         self.items.append(item)
  8.  
  9.         if self.current_max == None:
  10.             self.current_max = item
  11.         else:
  12.             self.current_max = max(item, self.current_max)
  13.  
  14.  
  15.     def pop(self):
  16.         if self.items:
  17.             self.items.pop()
  18.             self.current_max = max(items)
  19.  
  20.     def getMax(self):
  21.         if self.items:
  22.             return self.current_max
  23.  
  24.     def isEmpty(self):
  25.         return self.items == []
  26.  
  27.     def peek(self):
  28.         if self.items:
  29.             return self.items[-1]
  30.  
  31.     def clear(self):
  32.         self.items = []
  33.         self.current_max = None
  34.  
  35.     def __repr__(self):
  36.         return str(self.items)
Advertisement
Add Comment
Please, Sign In to add comment