mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
refactor: Replace 结点 with 节点 (#452)
* Replace 结点 with 节点 Update the footnotes in the figures * Update mindmap * Reduce the size of the mindmap.png
This commit is contained in:
@@ -12,7 +12,7 @@ def pre_order(root: TreeNode | None) -> None:
|
||||
""" 前序遍历 """
|
||||
if root is None:
|
||||
return
|
||||
# 访问优先级:根结点 -> 左子树 -> 右子树
|
||||
# 访问优先级:根节点 -> 左子树 -> 右子树
|
||||
res.append(root.val)
|
||||
pre_order(root=root.left)
|
||||
pre_order(root=root.right)
|
||||
@@ -21,7 +21,7 @@ def in_order(root: TreeNode | None) -> None:
|
||||
""" 中序遍历 """
|
||||
if root is None:
|
||||
return
|
||||
# 访问优先级:左子树 -> 根结点 -> 右子树
|
||||
# 访问优先级:左子树 -> 根节点 -> 右子树
|
||||
in_order(root=root.left)
|
||||
res.append(root.val)
|
||||
in_order(root=root.right)
|
||||
@@ -30,7 +30,7 @@ def post_order(root: TreeNode | None) -> None:
|
||||
""" 后序遍历 """
|
||||
if root is None:
|
||||
return
|
||||
# 访问优先级:左子树 -> 右子树 -> 根结点
|
||||
# 访问优先级:左子树 -> 右子树 -> 根节点
|
||||
post_order(root=root.left)
|
||||
post_order(root=root.right)
|
||||
res.append(root.val)
|
||||
@@ -47,17 +47,17 @@ if __name__ == "__main__":
|
||||
# 前序遍历
|
||||
res = []
|
||||
pre_order(root)
|
||||
print("\n前序遍历的结点打印序列 = ", res)
|
||||
print("\n前序遍历的节点打印序列 = ", res)
|
||||
assert res == [1, 2, 4, 5, 3, 6, 7]
|
||||
|
||||
# 中序遍历
|
||||
res.clear()
|
||||
in_order(root)
|
||||
print("\n中序遍历的结点打印序列 = ", res)
|
||||
print("\n中序遍历的节点打印序列 = ", res)
|
||||
assert res == [4, 2, 5, 1, 6, 3, 7]
|
||||
|
||||
# 后序遍历
|
||||
res.clear()
|
||||
post_order(root)
|
||||
print("\n后序遍历的结点打印序列 = ", res)
|
||||
print("\n后序遍历的节点打印序列 = ", res)
|
||||
assert res == [4, 5, 2, 6, 7, 3, 1]
|
||||
|
||||
Reference in New Issue
Block a user