1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| """ 栈 Copyright conghaoyuan """ class Stack: def __init__(self) -> None: self.stack = []
def print_stack(self): print(self.stack) def push(self, data): self.stack.append(data) def pop(self): if len(self.stack) == 0: print("stack empty") return return self.stack.pop()
if __name__ == '__main__': stack = Stack() stack.push(1) stack.push(2) stack.push(3) stack.push(4) stack.push(5) stack.print_stack() print(stack.pop()) print(stack.pop()) stack.print_stack()
|