mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +08:00
Update the comments in
binary_search_tree and avl_tree.
This commit is contained in:
@ -195,11 +195,11 @@ func (t *avlTree) search(val int) *TreeNode {
|
||||
cur := t.root
|
||||
// 循环查找,越过叶结点后跳出
|
||||
for cur != nil {
|
||||
// 目标结点在 root 的右子树中
|
||||
if cur.Val < val {
|
||||
// 目标结点在 cur 的右子树中
|
||||
cur = cur.Right
|
||||
} else if cur.Val > val {
|
||||
// 目标结点在 root 的左子树中
|
||||
// 目标结点在 cur 的左子树中
|
||||
cur = cur.Left
|
||||
} else {
|
||||
// 找到目标结点,跳出循环
|
||||
|
||||
@ -46,10 +46,10 @@ func (bst *binarySearchTree) search(num int) *TreeNode {
|
||||
// 循环查找,越过叶结点后跳出
|
||||
for node != nil {
|
||||
if node.Val < num {
|
||||
// 目标结点在 root 的右子树中
|
||||
// 目标结点在 cur 的右子树中
|
||||
node = node.Right
|
||||
} else if node.Val > num {
|
||||
// 目标结点在 root 的左子树中
|
||||
// 目标结点在 cur 的左子树中
|
||||
node = node.Left
|
||||
} else {
|
||||
// 找到目标结点,跳出循环
|
||||
|
||||
Reference in New Issue
Block a user