mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-04 19:20:52 +08:00
feat: add rust codes for avl tree (#605)
* feat: add rust codes for avl tree * fix a wrong usage of borrow method of RefCell * Update avl_tree.rs * fix comment indentation and field define of TreeNode --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -9,9 +9,10 @@ use std::collections::VecDeque;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub struct TreeNode {
|
||||
pub val: i32,
|
||||
pub high: i32,
|
||||
pub height: i32,
|
||||
pub parent: Option<Rc<RefCell<TreeNode>>>,
|
||||
pub left: Option<Rc<RefCell<TreeNode>>>,
|
||||
pub right: Option<Rc<RefCell<TreeNode>>>,
|
||||
@@ -21,7 +22,7 @@ impl TreeNode {
|
||||
pub fn new(val: i32) -> Rc<RefCell<Self>> {
|
||||
Rc::new(RefCell::new(Self {
|
||||
val,
|
||||
high: 0,
|
||||
height: 0,
|
||||
parent: None,
|
||||
left: None,
|
||||
right: None
|
||||
|
||||
Reference in New Issue
Block a user