|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
class Stack:
def __init__(self,start=[]):
self.stack = [] #请问为什么这里要这么定义列表?能不能self = []
for x in start:
self.push(x)
def push(self,obj):
self.stack.append(obj)
def isEmpty(self):
return not self.stack #栈空则返回True
def pop(self):
if not self.stack: #首先判断是否为空?
print('警告:栈为空!')
else:
return self.stack.pop()
def top(self):
if not self.stack:
print('警告:栈为空!')
else:
return self.stack[-1]
def bottom(self):
if not self.stack:
print('警告:栈为空!')
else:
return self.stack[0] |
|