mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-13 07:46:06 +00:00
build
This commit is contained in:
@@ -111,10 +111,10 @@ comments: true
|
||||
node := bst.root
|
||||
// 循环查找,越过叶节点后跳出
|
||||
for node != nil {
|
||||
if node.Val < num {
|
||||
if node.Val.(int) < num {
|
||||
// 目标节点在 cur 的右子树中
|
||||
node = node.Right
|
||||
} else if node.Val > num {
|
||||
} else if node.Val.(int) > num {
|
||||
// 目标节点在 cur 的左子树中
|
||||
node = node.Left
|
||||
} else {
|
||||
@@ -127,7 +127,7 @@ comments: true
|
||||
}
|
||||
```
|
||||
|
||||
=== "JavaScript"
|
||||
=== "JS"
|
||||
|
||||
```javascript title="binary_search_tree.js"
|
||||
/* 查找节点 */
|
||||
@@ -147,7 +147,7 @@ comments: true
|
||||
}
|
||||
```
|
||||
|
||||
=== "TypeScript"
|
||||
=== "TS"
|
||||
|
||||
```typescript title="binary_search_tree.ts"
|
||||
/* 查找节点 */
|
||||
@@ -422,7 +422,7 @@ comments: true
|
||||
return
|
||||
}
|
||||
pre = cur
|
||||
if cur.Val < num {
|
||||
if cur.Val.(int) < num {
|
||||
cur = cur.Right
|
||||
} else {
|
||||
cur = cur.Left
|
||||
@@ -430,7 +430,7 @@ comments: true
|
||||
}
|
||||
// 插入节点
|
||||
node := NewTreeNode(num)
|
||||
if pre.Val < num {
|
||||
if pre.Val.(int) < num {
|
||||
pre.Right = node
|
||||
} else {
|
||||
pre.Left = node
|
||||
@@ -438,7 +438,7 @@ comments: true
|
||||
}
|
||||
```
|
||||
|
||||
=== "JavaScript"
|
||||
=== "JS"
|
||||
|
||||
```javascript title="binary_search_tree.js"
|
||||
/* 插入节点 */
|
||||
@@ -464,7 +464,7 @@ comments: true
|
||||
}
|
||||
```
|
||||
|
||||
=== "TypeScript"
|
||||
=== "TS"
|
||||
|
||||
```typescript title="binary_search_tree.ts"
|
||||
/* 插入节点 */
|
||||
@@ -900,7 +900,7 @@ comments: true
|
||||
break
|
||||
}
|
||||
pre = cur
|
||||
if cur.Val < num {
|
||||
if cur.Val.(int) < num {
|
||||
// 待删除节点在右子树中
|
||||
cur = cur.Right
|
||||
} else {
|
||||
@@ -940,14 +940,14 @@ comments: true
|
||||
tmp = tmp.Left
|
||||
}
|
||||
// 递归删除节点 tmp
|
||||
bst.remove(tmp.Val)
|
||||
bst.remove(tmp.Val.(int))
|
||||
// 用 tmp 覆盖 cur
|
||||
cur.Val = tmp.Val
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
=== "JavaScript"
|
||||
=== "JS"
|
||||
|
||||
```javascript title="binary_search_tree.js"
|
||||
/* 删除节点 */
|
||||
@@ -996,7 +996,7 @@ comments: true
|
||||
}
|
||||
```
|
||||
|
||||
=== "TypeScript"
|
||||
=== "TS"
|
||||
|
||||
```typescript title="binary_search_tree.ts"
|
||||
/* 删除节点 */
|
||||
|
||||
Reference in New Issue
Block a user