mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-04 11:23:55 +08:00
* Review the EN heading format. * Fix pythontutor headings. * Fix pythontutor headings. * bug fixes * Fix headings in **/summary.md * Revisit the CN-to-EN translation for Python code using Claude-4.5 * Revisit the CN-to-EN translation for Java code using Claude-4.5 * Revisit the CN-to-EN translation for Cpp code using Claude-4.5. * Fix the dictionary. * Fix cpp code translation for the multipart strings. * Translate Go code to English. * Update workflows to test EN code. * Add EN translation for C. * Add EN translation for CSharp. * Add EN translation for Swift. * Trigger the CI check. * Revert. * Update en/hash_map.md * Add the EN version of Dart code. * Add the EN version of Kotlin code. * Add missing code files. * Add the EN version of JavaScript code. * Add the EN version of TypeScript code. * Fix the workflows. * Add the EN version of Ruby code. * Add the EN version of Rust code. * Update the CI check for the English version code. * Update Python CI check. * Fix cmakelists for en/C code. * Fix Ruby comments
39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
/**
|
|
* File: binary_tree.rs
|
|
* Created Time: 2023-02-27
|
|
* Author: xBLACKICEx (xBLACKICE@outlook.com)
|
|
*/
|
|
use std::rc::Rc;
|
|
use hello_algo_rust::include::{print_util, TreeNode};
|
|
|
|
/* Driver Code */
|
|
fn main() {
|
|
/* Initialize binary tree */
|
|
// Initialize nodes
|
|
let n1 = TreeNode::new(1);
|
|
let n2 = TreeNode::new(2);
|
|
let n3 = TreeNode::new(3);
|
|
let n4 = TreeNode::new(4);
|
|
let n5 = TreeNode::new(5);
|
|
// Build references (pointers) between nodes
|
|
n1.borrow_mut().left = Some(Rc::clone(&n2));
|
|
n1.borrow_mut().right = Some(Rc::clone(&n3));
|
|
n2.borrow_mut().left = Some(Rc::clone(&n4));
|
|
n2.borrow_mut().right = Some(Rc::clone(&n5));
|
|
println!("\nInitialize binary tree\n");
|
|
print_util::print_tree(&n1);
|
|
|
|
// Insert node and delete node
|
|
let p = TreeNode::new(0);
|
|
// Delete node
|
|
p.borrow_mut().left = Some(Rc::clone(&n2));
|
|
n1.borrow_mut().left = Some(Rc::clone(&p));
|
|
println!("\nAfter inserting node P\n");
|
|
print_util::print_tree(&n1);
|
|
// Remove node P
|
|
drop(p);
|
|
n1.borrow_mut().left = Some(Rc::clone(&n2));
|
|
println!("\nAfter removing node P\n");
|
|
print_util::print_tree(&n1);
|
|
}
|