Update array stack.

This commit is contained in:
Yudong Jin
2022-12-20 14:13:21 +08:00
parent fe7564d54d
commit fa3eff81d1
9 changed files with 46 additions and 43 deletions

View File

@ -27,14 +27,17 @@ class ArrayStack:
""" 出栈 """
def pop(self):
assert not self.is_empty(), "栈为空"
return self.__stack.pop()
""" 访问栈顶元素 """
def peek(self):
assert not self.is_empty(), "栈为空"
return self.__stack[-1]
""" 访问索引 index 处元素 """
def get(self, index):
assert index < self.size(), "索引越界"
return self.__stack[index]
""" 返回列表用于打印 """