Created
April 20, 2019 05:10
-
-
Save satellitex/06eb5e154dd2be05e6d6095a92a88978 to your computer and use it in GitHub Desktop.
Rust で木を表現/生成。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
enum Tree { | |
Leaf(i32), | |
Node(Box<Tree>, Box<Tree>), | |
} | |
fn main() { | |
let mut tree = Tree::Leaf(0); | |
for i in vec!{0,1,2,3,4,5} { | |
tree = Tree::Node(Box::<Tree>::new(tree), | |
Box::<Tree>::new(Tree::Leaf(i * 10))); | |
} | |
println!("{:?}",tree); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment