def init(self, max):
self.maxstacksize = 10
self.s = [None for x in range(0, self.maxstacksize)]
self.top = -1
def isemptystack(self):
if self.top == -1:
iTop = True
else:
iTop = False
return iTop
def pushstack(self, x):
if self.top < self.maxstacksize-1:
self.top = self.top+1
self.s[self.top] = x
else:
print("栈满")
return
def popstack(self):
if self.isemptystack():
print("栈为空")
return
else:
itop = self.top
self.top = self.yop-1
return self.s[itop]
def gettopstack(self):
if self.isemptystack():
print("栈为空")
return
else:
return self.s[self.top]
def stacktraverse(self):
if self.isemptystack(self):
print("栈为空")
return
else:
for i in range(0, self.top+1):
print(self.s[i], end=' ')
def createstackbyinput(self):
data = input("请输入元素(继续输入请按回车键,结束请输入‘#’):")
while data != '#':
self.pushstack(data)
data = input("请输入元素: ")
ss='SequenceStack'()
ss.createstackbyinput()
print("栈内的元素为: ", end=' ')
ss.stacktraverse()