in reply to representing a tree
Now, you have a tree. Do what you want with it.use Tree; my @data = ( [ 1,3 ], [ 1,4 ], [ 1,5 ], [ 3,8 ], [ 3,9 ], [ 4,11 ], [ 4,18 ], [ 8,14 ], [ 8,15 ], [ 5,17 ], [ 5,16 ], [ 17,21 ], ); my %nodes; foreach my $edge ( @data ) { my ($parent_id, $child_id) = @$edge; my $parent = $nodes{$parent_id} ||= Tree->new( $parent_id ); my $child = $nodes{$child_id} ||= Tree->new( $child_id ); $parent->add_child( $child ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: representing a tree
by Anonymous Monk on Jul 03, 2008 at 13:09 UTC |