mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-05 21:19:41 +08:00
Update the structure of the chapter
of binary tree.
This commit is contained in:
@ -54,13 +54,6 @@ class ArrayQueue:
|
||||
return False
|
||||
return self.__nums[self.__front]
|
||||
|
||||
""" 访问指定位置元素 """
|
||||
def get(self, index):
|
||||
if index >= self.size():
|
||||
print("索引越界")
|
||||
return False
|
||||
return self.__nums[(self.__front + index) % self.capacity()]
|
||||
|
||||
""" 返回列表用于打印 """
|
||||
def to_list(self):
|
||||
res = [0] * self.size()
|
||||
@ -88,10 +81,6 @@ if __name__ == "__main__":
|
||||
peek = queue.peek()
|
||||
print("队首元素 peek =", peek)
|
||||
|
||||
""" 访问索引 index 处元素 """
|
||||
num = queue.get(3)
|
||||
print("队列索引 3 处的元素为 num =", num)
|
||||
|
||||
""" 元素出队 """
|
||||
poll = queue.poll()
|
||||
print("出队元素 poll =", poll)
|
||||
|
@ -34,11 +34,6 @@ class ArrayStack:
|
||||
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]
|
||||
|
||||
""" 返回列表用于打印 """
|
||||
def to_list(self):
|
||||
@ -62,10 +57,6 @@ if __name__ == "__main__":
|
||||
peek = stack.peek()
|
||||
print("栈顶元素 peek =", peek)
|
||||
|
||||
""" 访问索引 index 处元素 """
|
||||
num = stack.get(3)
|
||||
print("栈索引 3 处的元素为 num =", num)
|
||||
|
||||
""" 元素出栈 """
|
||||
pop = stack.pop()
|
||||
print("出栈元素 pop =", pop)
|
||||
|
Reference in New Issue
Block a user