This commit is contained in:
krahets
2023-10-03 03:49:55 +08:00
parent 256ce30a95
commit 49ad0a6422
12 changed files with 166 additions and 16 deletions
+21
View File
@@ -161,7 +161,28 @@ AVL 树既是二叉搜索树也是平衡二叉树,同时满足这两类二叉
=== "Rust"
```rust title=""
use std::rc::Rc;
use std::cell::RefCell;
/* AVL 树节点结构体 */
struct TreeNode {
val: i32, // 节点值
height: i32, // 节点高度
left: Option<Rc<RefCell<TreeNode>>>, // 左子节点
right: Option<Rc<RefCell<TreeNode>>>, // 右子节点
}
impl TreeNode {
/* 构造方法 */
fn new(val: i32) -> Rc<RefCell<Self>> {
Rc::new(RefCell::new(Self {
val,
height: 0,
left: None,
right: None
}))
}
}
```
=== "C"