feat: Add rust code in binary_tree.md (#759)

* feat: Add binary_tree.md

* Update binary_tree.md

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
lucas 2023-10-03 00:43:24 +08:00 committed by GitHub
parent d86cb0ee5d
commit 0e3d2ce4bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,7 +58,7 @@
Left *TreeNode
Right *TreeNode
}
/* 节点初始化方法 */
/* 构造方法 */
func NewTreeNode(v int) *TreeNode {
return &TreeNode{
Left: nil, // 左子节点指针
@ -134,7 +134,7 @@
use std::rc::Rc;
use std::cell::RefCell;
/* 二叉树节点类型 */
/* 二叉树节点结构体 */
struct TreeNode {
val: i32, // 节点值
left: Option<Rc<RefCell<TreeNode>>>, // 左子节点引用
@ -142,7 +142,7 @@
}
impl TreeNode {
/* 二叉树节点构造方法 */
/* 构造方法 */
fn new(val: i32) -> Rc<RefCell<Self>> {
Rc::new(RefCell::new(Self {
val,