1extern crate xtree;
2
3use xtree::*;
4
5fn main(){
6 let mut tree =
7 tr!(1)
8 / (tr!(2)
9 / tr!(5)
10 / tr!(6))
11 / (tr!(3)
12 / tr!(7)
13 / tr!(8))
14 / tr!(4);
15
16 let mut cursor = tree.cursor_mut();
17 cursor.move_child(0);
18 *cursor.current() = 10;
19 cursor.move_parent();
20 cursor.move_child(1);
21 let sub_tree = cursor.remove().unwrap();
22 for (depth,node) in sub_tree.df_iter().depth(){
23 for _ in 0..depth {
24 print!("-");
25 }
26 println!("{}",node);
27 }
28
29 let mut cursor = tree.cursor();
30 println!("children of root:");
31 for child in cursor.children() {
32 print!("{} ",child)
33 }
34 println!();
35 println!("root:{}",cursor.current());
36 cursor.move_child(0);
37 println!("first child:{}",cursor.current());
38 cursor.move_parent();
39 cursor.move_child(1);
40 println!("second child:{}",cursor.current());
41
42 for itr in tree.df_iter_mut() {
43 *itr += 1;
44 print!("{} ",itr);
45 }
46 println!();
47
48 for (depth,node) in tree.df_iter().depth(){
49 for _ in 0..depth {
50 print!("-");
51 }
52 println!("{}",node);
53 }
54
55 for itr in tree.bf_iter(){
56 print!("{} ",itr);
57 }
58}