class Stack:
__slots__ = ('__items')
def __init__(self):
'''初始化栈为空列表'''
self.__items = []
def is_empty(self):
"""判断是否为空栈, 返回 bool 值"""
return self.__items == []
def peek(self):
"""查看栈顶"""
return self.__items[len(self.__items) - 1]
def size(self):
"""查看栈大小"""
return len(self.__items)
def push(self, item):
"""入栈"""
self.__items.append(item)
def pop(self):
"""出栈"""
return self.__items.pop()
python 简单模拟stack
最新推荐文章于 2024-01-18 15:15:54 发布