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])
定义一个栈(Stack)类,用于模拟一种具有后进先出(LIFO)特性的数据结构
最新推荐文章于 2024-02-25 08:12:58 发布