This commit is contained in:
krahets
2024-03-18 03:11:07 +08:00
parent bc0054a577
commit 54c7448946
48 changed files with 577 additions and 408 deletions

View File

@ -18,7 +18,7 @@ comments: true
<p align="center"> 图 7-12 &nbsp; 完美二叉树的数组表示 </p>
**映射公式的角色相当于链表中的指针**。给定数组中的任意一个节点,我们都可以通过映射公式来访问它的左(右)子节点。
**映射公式的角色相当于链表中的引用**。给定数组中的任意一个节点,我们都可以通过映射公式来访问它的左(右)子节点。
## 7.3.2 &nbsp; 表示任意二叉树

View File

@ -1819,6 +1819,7 @@ AVL 树的节点插入操作与二叉搜索树在主体上类似。唯一的区
}
}
Self::update_height(Some(node.clone())); // 更新节点高度
/* 2. 执行旋转操作,使该子树重新恢复平衡 */
node = Self::rotate(Some(node)).unwrap();
// 返回子树的根节点
@ -2343,6 +2344,7 @@ AVL 树的节点插入操作与二叉搜索树在主体上类似。唯一的区
node.borrow_mut().val = temp.borrow().val;
}
Self::update_height(Some(node.clone())); // 更新节点高度
/* 2. 执行旋转操作,使该子树重新恢复平衡 */
node = Self::rotate(Some(node)).unwrap();
// 返回子树的根节点

View File

@ -1291,8 +1291,8 @@ comments: true
/* 删除节点 */
pub fn remove(&mut self, num: i32) {
// 若树为空,直接提前返回
if self.root.is_none() {
return;
if self.root.is_none() {
return;
}
let mut cur = self.root.clone();
let mut pre = None;

View File

@ -233,13 +233,14 @@ comments: true
// 初始化一个列表,用于保存遍历序列
let mut vec = Vec::new();
while let Some(node) = que.pop_front() { // 队列出队
vec.push(node.borrow().val); // 保存节点值
while let Some(node) = que.pop_front() {
// 队列出队
vec.push(node.borrow().val); // 保存节点值
if let Some(left) = node.borrow().left.as_ref() {
que.push_back(Rc::clone(left)); // 左子节点入队
que.push_back(Rc::clone(left)); // 左子节点入队
}
if let Some(right) = node.borrow().right.as_ref() {
que.push_back(Rc::clone(right)); // 右子节点入队
que.push_back(Rc::clone(right)); // 右子节点入队
};
}
vec