fix binary_search_tree code

This commit is contained in:
krahets
2023-08-31 02:31:31 +08:00
parent f7ab4797bf
commit 628d8a516b
14 changed files with 195 additions and 227 deletions

View File

@ -74,8 +74,9 @@ impl BinarySearchTree {
/* 插入节点 */
pub fn insert(&mut self, num: i32) {
// 若树为空,直接提前返回
// 若树为空,则初始化根节点
if self.root.is_none() {
self.root = TreeNode::new(num);
return;
}
let mut cur = self.root.clone();