in reply to Re^2: how to construct tree from parent pointer list
in thread how to construct tree from parent pointer list
Like any other tree.
sub visit_preorder { my ($cb, node, $depth) = @_; $depth ||= 0; $cb->($node, $depth); visit_preorder($cb, $_, $depth+1) for $node->children(); } sub visit_postorder { my ($cb, $node, $depth) = @_; $depth ||= 0; visit_postorder($cb, $_, $depth+1) for $node->children(); $cb->($node, $depth); } visit_preorder(sub { my ($node, $depth) = @_; ... }, $root);
It's odd that the module doesn't provide this for you.
What's wrong with the solutions we've already customised for you?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: how to construct tree from parent pointer list
by bryank (Acolyte) on Jun 30, 2009 at 14:18 UTC | |
by ikegami (Patriarch) on Jun 30, 2009 at 15:49 UTC | |
Re^4: how to construct tree from parent pointer list
by bryank (Acolyte) on Jun 30, 2009 at 16:00 UTC | |
by ikegami (Patriarch) on Jun 30, 2009 at 19:21 UTC |
In Section
Seekers of Perl Wisdom