发布时间:2019-09-21 11:14:23编辑:auto阅读(2058)
# -*- coding:utf-8 -*- class Stack(): #初始化栈,并给定栈的大小 def __init__(self,size): self.stack=[] self.size=size self.top=-1 #判断栈是否满了,栈满返回True def Full(self): if self.top==(self.size-1): return True else: return False #判断栈是否为空,为空返回True def Empty(self): if self.top==-1: return True else: return False #入栈 def stackin(self,content): if self.Full(): print 'The stack is full!' else: self.stack.append(content) self.top+=1 #出栈 def stackout(self): if self.Empty(): print 'The stack is empty!' return None else: content=self.stack[self.top] self.stack.pop(self.top) self.top-=1 return content #遍历栈 def stackall(self): if self.Empty(): print 'The stack is Empty!' else: while self.top>=0: print self.stack[self.top] self.top-=1
上一篇: Python同步文件
下一篇: H3C nqa 配置
49789
49019
39706
36753
31146
27978
26944
21751
21662
20013
108°
742°
1323°
1263°
1122°
2260°
1348°
1954°
2207°
1715°