-
-
Save huonw/9721035 to your computer and use it in GitHub Desktop.
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
extern crate collections; | |
use collections::hashmap::HashMap; | |
struct Node { | |
data : ~str, | |
children : ~HashMap<~str, Node>, | |
} | |
impl Node { | |
fn new(data: ~str) -> Node { | |
Node{ data: data, children: ~HashMap::new() } | |
} | |
} | |
fn main() { | |
let v = ~[~"Hello", ~"Tree", ~"World"]; | |
let mut main = Node::new(~"Testing"); | |
let mut ptr = &mut main; | |
for a in v.move_iter() { | |
ptr = ptr.children.find_or_insert(a.clone(), Node::new(a)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment