doc(code): modify go code in docs

This commit is contained in:
reanon
2023-01-08 20:29:13 +08:00
parent 33e2c4f4d3
commit 0243957015
8 changed files with 143 additions and 117 deletions

View File

@ -103,7 +103,7 @@ comments: true
```go title="binary_search_tree.go"
/* 查找结点 */
func (bst *BinarySearchTree) Search(num int) *TreeNode {
func (bst *binarySearchTree) search(num int) *TreeNode {
node := bst.root
// 循环查找,越过叶结点后跳出
for node != nil {
@ -299,7 +299,7 @@ comments: true
```go title="binary_search_tree.go"
/* 插入结点 */
func (bst *BinarySearchTree) Insert(num int) *TreeNode {
func (bst *binarySearchTree) insert(num int) *TreeNode {
cur := bst.root
// 若树为空,直接提前返回
if cur == nil {
@ -609,7 +609,7 @@ comments: true
```go title="binary_search_tree.go"
/* 删除结点 */
func (bst *BinarySearchTree) Remove(num int) *TreeNode {
func (bst *binarySearchTree) remove(num int) *TreeNode {
cur := bst.root
// 若树为空,直接提前返回
if cur == nil {
@ -653,10 +653,10 @@ comments: true
// 子结点数为 2
} else {
// 获取中序遍历中待删除结点 cur 的下一个结点
next := bst.GetInOrderNext(cur)
next := bst.getInOrderNext(cur)
temp := next.Val
// 递归删除结点 next
bst.Remove(next.Val)
bst.remove(next.Val)
// 将 next 的值复制给 cur
cur.Val = temp
}