simplify the tree structure code

This commit is contained in:
Able 2021-11-30 13:52:31 -06:00
parent f5e30e15fb
commit e9e3749d85

View file

@ -15,7 +15,7 @@ impl File {
fn new(name: String) -> Self { fn new(name: String) -> Self {
Self { Self {
size: *&name.len() as u64, size: *&name.len() as u64,
name: name, name,
} }
} }
} }
@ -36,13 +36,9 @@ fn main() {
for x in tree.traverse_pre_order(&root_id.unwrap()).unwrap() { for x in tree.traverse_pre_order(&root_id.unwrap()).unwrap() {
println!("Parent: {:?}", x.data()); println!("Parent: {:?}", x.data());
for y in x.children() { for y in x.children() {
if tree.get(y).unwrap().children().is_empty() {
println!("No Children");
} else {
println!(" Children: {:?}", tree.get(y).unwrap().data()); println!(" Children: {:?}", tree.get(y).unwrap().data());
} }
} }
}
} }
fn generate_tree() { fn generate_tree() {