diff --git a/codes/python/chapter_tree/avl_tree.py b/codes/python/chapter_tree/avl_tree.py index 6fe4676fc..27def6274 100644 --- a/codes/python/chapter_tree/avl_tree.py +++ b/codes/python/chapter_tree/avl_tree.py @@ -15,11 +15,7 @@ class AVLTree: def __init__(self, root: TreeNode | None = None): """构造方法""" - self.__root = root - - @property - def root(self) -> TreeNode | None: - return self.__root + self.root = root def height(self, node: TreeNode | None) -> int: """获取节点高度""" @@ -94,7 +90,7 @@ class AVLTree: def insert(self, val) -> None: """插入节点""" - self.__root = self.__insert_helper(self.__root, val) + self.root = self.__insert_helper(self.root, val) def __insert_helper(self, node: TreeNode | None, val: int) -> TreeNode: """递归插入节点(辅助方法)""" @@ -115,7 +111,7 @@ class AVLTree: def remove(self, val: int) -> None: """删除节点""" - self.__root = self.__remove_helper(self.__root, val) + self.root = self.__remove_helper(self.root, val) def __remove_helper(self, node: TreeNode | None, val: int) -> TreeNode | None: """递归删除节点(辅助方法)""" @@ -149,7 +145,7 @@ class AVLTree: def search(self, val: int) -> TreeNode | None: """查找节点""" - cur = self.__root + cur = self.root # 循环查找,越过叶节点后跳出 while cur is not None: # 目标节点在 cur 的右子树中 diff --git a/codes/python/chapter_tree/binary_search_tree.py b/codes/python/chapter_tree/binary_search_tree.py index 4384f817c..d34496af8 100644 --- a/codes/python/chapter_tree/binary_search_tree.py +++ b/codes/python/chapter_tree/binary_search_tree.py @@ -16,7 +16,7 @@ class BinarySearchTree: def __init__(self, nums: list[int]) -> None: """构造方法""" nums.sort() - self.__root = self.build_tree(nums, 0, len(nums) - 1) + self.root = self.build_tree(nums, 0, len(nums) - 1) def build_tree( self, nums: list[int], start_index: int, end_index: int @@ -37,10 +37,6 @@ class BinarySearchTree: ) return root - @property - def root(self) -> TreeNode | None: - return self.__root - def search(self, num: int) -> TreeNode | None: """查找节点""" cur: TreeNode | None = self.root @@ -119,7 +115,7 @@ class BinarySearchTree: pre.right = child else: # 若删除节点为根节点,则重新指定根节点 - self.__root = child + self.root = child # 子节点数量 = 2 else: # 获取中序遍历中 cur 的下一个节点 diff --git a/docs/chapter_computational_complexity/index.md b/docs/chapter_computational_complexity/index.md index 80bc79982..54af4cbd8 100644 --- a/docs/chapter_computational_complexity/index.md +++ b/docs/chapter_computational_complexity/index.md @@ -1,7 +1,7 @@ -# 复杂度分析 +# 复杂度
-![复杂度分析](../assets/covers/chapter_complexity_analysis.jpg){ width="70%" } +![复杂度](../assets/covers/chapter_complexity_analysis.jpg){ width="70%" }
diff --git a/docs/chapter_data_structure/index.md b/docs/chapter_data_structure/index.md index 57c75245a..1f5d9eec3 100644 --- a/docs/chapter_data_structure/index.md +++ b/docs/chapter_data_structure/index.md @@ -1,4 +1,4 @@ -# 数据结构简介 +# 数据结构