class Lstack():
def __init__(self,top=-1,full=20):
self._top = top
self._stack=[]
self.full = full
def is__full(self):
return self.full == self._top+1
def is_empty(self):
return self._top == -1
def push(self,x):
if self.full == self._top+1:
print("堆栈已满")
else:
self._stack.append(x)
self._top += 1
def pop(self):
if self._top == -1:
print("堆栈为空,不可弹出")
else:
top =self._top
self._top -= 1
return self._stack.pop(top) # 这里一定要把top的元素弹出,而不是单纯的访
栈的顺序表实现
猜你喜欢
转载自blog.csdn.net/tommy1295/article/details/80931967
今日推荐
周排行