defpop(self) -> int: """ Removes the element on top of the stack and returns that element. """ # print("--> master",self.master) # print("--> aux",self.aux) res = self.master.pop(0)
# Your MyStack object will be instantiated and called as such: # obj = MyStack() # obj.push(x) # param_2 = obj.pop() # param_3 = obj.top() # param_4 = obj.empty()
def__init__(self): """ Initialize your data structure here. """ self.master = list()
defpush(self, x: int) -> None: """ Push element x onto stack. """ # print("这里是push") self.master.append(x)
# 如果超过一个元素 for i inrange(1,len(self.master)): self.master.append(self.master.pop(0))
defpop(self) -> int: """ Removes the element on top of the stack and returns that element. """ res = self.master.pop(0) return res
deftop(self) -> int: """ Get the top element. """ return self.master[0]
defempty(self) -> bool: """ Returns whether the stack is empty. """ returnFalseiflen(self.master) elseTrue
# Your MyStack object will be instantiated and called as such: # obj = MyStack() # obj.push(x) # param_2 = obj.pop() # param_3 = obj.top() # param_4 = obj.empty()