diff --git a/codes/cpp/chapter_tree/binary_search_tree.cpp b/codes/cpp/chapter_tree/binary_search_tree.cpp index fbbed9e9..cd6a712d 100644 --- a/codes/cpp/chapter_tree/binary_search_tree.cpp +++ b/codes/cpp/chapter_tree/binary_search_tree.cpp @@ -86,9 +86,9 @@ public: // 找到待删除结点,跳出循环 if (cur->val == num) break; pre = cur; - // 待删除结点在 root 的右子树中 + // 待删除结点在 cur 的右子树中 if (cur->val < num) cur = cur->right; - // 待删除结点在 root 的左子树中 + // 待删除结点在 cur 的左子树中 else cur = cur->left; } // 若无待删除结点,则直接返回 diff --git a/codes/csharp/chapter_tree/binary_search_tree.cs b/codes/csharp/chapter_tree/binary_search_tree.cs index e12cdd42..cb832769 100644 --- a/codes/csharp/chapter_tree/binary_search_tree.cs +++ b/codes/csharp/chapter_tree/binary_search_tree.cs @@ -94,9 +94,9 @@ namespace hello_algo.chapter_tree // 找到待删除结点,跳出循环 if (cur.val == num) break; pre = cur; - // 待删除结点在 root 的右子树中 + // 待删除结点在 cur 的右子树中 if (cur.val < num) cur = cur.right; - // 待删除结点在 root 的左子树中 + // 待删除结点在 cur 的左子树中 else cur = cur.left; } // 若无待删除结点,则直接返回 diff --git a/codes/java/chapter_tree/binary_search_tree.java b/codes/java/chapter_tree/binary_search_tree.java index a3b0f758..a0a554e3 100644 --- a/codes/java/chapter_tree/binary_search_tree.java +++ b/codes/java/chapter_tree/binary_search_tree.java @@ -83,9 +83,9 @@ class BinarySearchTree { // 找到待删除结点,跳出循环 if (cur.val == num) break; pre = cur; - // 待删除结点在 root 的右子树中 + // 待删除结点在 cur 的右子树中 if (cur.val < num) cur = cur.right; - // 待删除结点在 root 的左子树中 + // 待删除结点在 cur 的左子树中 else cur = cur.left; } // 若无待删除结点,则直接返回 diff --git a/codes/javascript/chapter_tree/binary_search_tree.js b/codes/javascript/chapter_tree/binary_search_tree.js index 9c808aaa..d619ab9f 100644 --- a/codes/javascript/chapter_tree/binary_search_tree.js +++ b/codes/javascript/chapter_tree/binary_search_tree.js @@ -80,9 +80,9 @@ function remove(num) { // 找到待删除结点,跳出循环 if (cur.val === num) break; pre = cur; - // 待删除结点在 root 的右子树中 + // 待删除结点在 cur 的右子树中 if (cur.val < num) cur = cur.right; - // 待删除结点在 root 的左子树中 + // 待删除结点在 cur 的左子树中 else cur = cur.left; } // 若无待删除结点,则直接返回 diff --git a/codes/python/chapter_tree/binary_search_tree.py b/codes/python/chapter_tree/binary_search_tree.py index 8817d4a5..fdedf6c9 100644 --- a/codes/python/chapter_tree/binary_search_tree.py +++ b/codes/python/chapter_tree/binary_search_tree.py @@ -94,9 +94,9 @@ class BinarySearchTree: if cur.val == num: break pre = cur - if cur.val < num: # 待删除结点在 root 的右子树中 + if cur.val < num: # 待删除结点在 cur 的右子树中 cur = cur.right - else: # 待删除结点在 root 的左子树中 + else: # 待删除结点在 cur 的左子树中 cur = cur.left # 若无待删除结点,则直接返回 diff --git a/codes/typescript/chapter_tree/binary_search_tree.ts b/codes/typescript/chapter_tree/binary_search_tree.ts index 9adf8cd1..a19ea32a 100644 --- a/codes/typescript/chapter_tree/binary_search_tree.ts +++ b/codes/typescript/chapter_tree/binary_search_tree.ts @@ -97,9 +97,9 @@ function remove(num: number): TreeNode | null { } pre = cur; if (cur.val < num) { - cur = cur.right as TreeNode; // 待删除结点在 root 的右子树中 + cur = cur.right as TreeNode; // 待删除结点在 cur 的右子树中 } else { - cur = cur.left as TreeNode; // 待删除结点在 root 的左子树中 + cur = cur.left as TreeNode; // 待删除结点在 cur 的左子树中 } } // 若无待删除结点,则直接返回 diff --git a/docs/chapter_tree/binary_search_tree.md b/docs/chapter_tree/binary_search_tree.md index ca8a9202..393221b7 100644 --- a/docs/chapter_tree/binary_search_tree.md +++ b/docs/chapter_tree/binary_search_tree.md @@ -479,9 +479,9 @@ comments: true // 找到待删除结点,跳出循环 if (cur.val == num) break; pre = cur; - // 待删除结点在 root 的右子树中 + // 待删除结点在 cur 的右子树中 if (cur.val < num) cur = cur.right; - // 待删除结点在 root 的左子树中 + // 待删除结点在 cur 的左子树中 else cur = cur.left; } // 若无待删除结点,则直接返回 @@ -523,9 +523,9 @@ comments: true // 找到待删除结点,跳出循环 if (cur->val == num) break; pre = cur; - // 待删除结点在 root 的右子树中 + // 待删除结点在 cur 的右子树中 if (cur->val < num) cur = cur->right; - // 待删除结点在 root 的左子树中 + // 待删除结点在 cur 的左子树中 else cur = cur->left; } // 若无待删除结点,则直接返回 @@ -571,9 +571,9 @@ comments: true if cur.val == num: break pre = cur - if cur.val < num: # 待删除结点在 root 的右子树中 + if cur.val < num: # 待删除结点在 cur 的右子树中 cur = cur.right - else: # 待删除结点在 root 的左子树中 + else: # 待删除结点在 cur 的左子树中 cur = cur.left # 若无待删除结点,则直接返回 @@ -673,9 +673,9 @@ comments: true // 找到待删除结点,跳出循环 if (cur.val === num) break; pre = cur; - // 待删除结点在 root 的右子树中 + // 待删除结点在 cur 的右子树中 if (cur.val < num) cur = cur.right; - // 待删除结点在 root 的左子树中 + // 待删除结点在 cur 的左子树中 else cur = cur.left; } // 若无待删除结点,则直接返回 @@ -721,9 +721,9 @@ comments: true } pre = cur; if (cur.val < num) { - cur = cur.right as TreeNode; // 待删除结点在 root 的右子树中 + cur = cur.right as TreeNode; // 待删除结点在 cur 的右子树中 } else { - cur = cur.left as TreeNode; // 待删除结点在 root 的左子树中 + cur = cur.left as TreeNode; // 待删除结点在 cur 的左子树中 } } // 若无待删除结点,则直接返回 @@ -776,9 +776,9 @@ comments: true // 找到待删除结点,跳出循环 if (cur.val == num) break; pre = cur; - // 待删除结点在 root 的右子树中 + // 待删除结点在 cur 的右子树中 if (cur.val < num) cur = cur.right; - // 待删除结点在 root 的左子树中 + // 待删除结点在 cur 的左子树中 else cur = cur.left; } // 若无待删除结点,则直接返回