mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 21:24:53 +08:00
make dfs same as c/c++ and other small improvement (#1543)
This commit is contained in:
@ -126,7 +126,7 @@ impl BinarySearchTree {
|
||||
// 删除节点 cur
|
||||
if !Rc::ptr_eq(&cur, self.root.as_ref().unwrap()) {
|
||||
let left = pre.borrow().left.clone();
|
||||
if left.is_some() && Rc::ptr_eq(&left.as_ref().unwrap(), &cur) {
|
||||
if left.is_some() && Rc::ptr_eq(left.as_ref().unwrap(), &cur) {
|
||||
pre.borrow_mut().left = child;
|
||||
} else {
|
||||
pre.borrow_mut().right = child;
|
||||
@ -147,11 +147,11 @@ impl BinarySearchTree {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let tmpval = tmp.unwrap().borrow().val;
|
||||
let tmp_val = tmp.unwrap().borrow().val;
|
||||
// 递归删除节点 tmp
|
||||
self.remove(tmpval);
|
||||
self.remove(tmp_val);
|
||||
// 用 tmp 覆盖 cur
|
||||
cur.borrow_mut().val = tmpval;
|
||||
cur.borrow_mut().val = tmp_val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user