|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
版主程序:
class Stack:
def __init__(self, start=[]):
self.stack = []
for x in start:
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:
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]
我的程序:
class Stack:
def __init__(self,start=[]):
self.start=[]
def isEmpty(self):
if len(self.start)!=0:
return False
else:
return True
def push(self,x):
self.start.append(x)
def pop(self):
if self.inEmpty():
return"警告,Stack为空"
else:
return self.start.pop()
def top(self):
if self.isEmpty():
return"警告,Stack为空"
else:
return self.start[0]
def bottom(self):
if self.isEmpty():
return"警告,Stack为空"
else:
return self.start[1]
============================================
版主中 for x in start:
self.push(x)
起什么作用?
我的程序没有这个似乎也能用?
|
|