mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-07 06:44:57 +08:00
Update array stack.
This commit is contained in:
@ -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]
|
||||
|
||||
""" 返回列表用于打印 """
|
||||
|
Reference in New Issue
Block a user