''' 1.首先确认栈的概念,先进后出 2.初始化的时候如果给了一个数组那么就要将数组进栈 ''' class Stack: def __init__(self,start=[]): self.stack=[] #初始化一个数组,用于存储栈成员 for x in start: #遍历初始化时给定的数组 self.push(x) #调用进栈方法 def isEmpty(self): #判断是否是空的栈 return not self.stack # not 0 为True not 1..为True
5.1.1. Using Lists as Stacks The list methods make it very easy to use a list as a stack, where the last element added is the first element retrieved ("last-in, first-out"). To add an item to the top of the stack, use append(). To retrieve an it