mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-05 03:30:30 +08:00
fix binary_search_tree code
This commit is contained in:
@@ -54,9 +54,11 @@ class BinarySearchTree {
|
||||
|
||||
/* 插入节点 */
|
||||
public void insert(int num) {
|
||||
// 若树为空,直接提前返回
|
||||
if (root == null)
|
||||
// 若树为空,则初始化根节点
|
||||
if (root == null) {
|
||||
root = new TreeNode(num);
|
||||
return;
|
||||
}
|
||||
TreeNode? cur = root, pre = null;
|
||||
// 循环查找,越过叶节点后跳出
|
||||
while (cur != null) {
|
||||
|
||||
Reference in New Issue
Block a user