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:
Night Cruising
2023-07-16 01:32:43 +08:00
committed by GitHub
parent b1f8857212
commit f5ea4fa1c6
3 changed files with 304 additions and 2 deletions

View File

@@ -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