mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
fix binary_search_tree code
This commit is contained in:
@ -70,9 +70,11 @@ TreeNode *search(binarySearchTree *bst, int num) {
|
||||
|
||||
/* 插入节点 */
|
||||
void insert(binarySearchTree *bst, int num) {
|
||||
// 若树为空,直接提前返回
|
||||
if (bst->root == NULL)
|
||||
// 若树为空,则初始化根节点
|
||||
if (bst->root == NULL) {
|
||||
bst->root = newTreeNode(num);
|
||||
return;
|
||||
}
|
||||
TreeNode *cur = bst->root, *pre = NULL;
|
||||
// 循环查找,越过叶节点后跳出
|
||||
while (cur != NULL) {
|
||||
|
||||
Reference in New Issue
Block a user