Skip to content

Instantly share code, notes, and snippets.

@satellitex
Created April 20, 2019 05:10
Show Gist options
  • Save satellitex/06eb5e154dd2be05e6d6095a92a88978 to your computer and use it in GitHub Desktop.
Save satellitex/06eb5e154dd2be05e6d6095a92a88978 to your computer and use it in GitHub Desktop.
Rust で木を表現/生成。
#[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