版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Einstellung/article/details/82111230
class Stack:
def __init__(self, stack):
self.stack = []
for x in stack:
self.push(x)
def isEmpty(self):
return not self.stack
def push(self, obj):
self.stack.append(obj)
def pop(self):
if not self.stack:
print("当前栈为空")
else:
self.stack.pop()
def top(self):
if not self.stack:
print("当前栈为空")
else:
print(self.stack[-1])
def bottom(self):
if not self.stack:
print("当前栈为空")
else:
print(self.stack[0])