![]() |
![]()
| ![]() |
![]()
NAMETree::Binary::Visitor::PreOrderTraversal - Visitor object for Tree::Binary objects SYNOPSISFor a complete example, see also "SYNOPSIS" in Tree::Binary. use Tree::Binary; use Tree::Binary::Visitor::PreOrderTraversal; # create a visitor instance my $visitor = Tree::Binary::Visitor::PreOrderTraversal->new(); # create a tree to visit # this is an expression tree # representing ((2 + 2) * (4 + 5)) my $btree = Tree::Binary->new("*") ->setLeft(Tree::Binary->new("+") ->setLeft(Tree::Binary->new("2")) ->setRight(Tree::Binary->new("2"))) ->setRight(Tree::Binary->new("+") ->setLeft(Tree::Binary->new("4")) ->setRight(Tree::Binary->new("5"))); # by default this will collect all the # node values in depth-first order into # our results $tree->accept($visitor); # get our results and print them print join ", ", $visitor->getResults(); # prints "*, +, 2, 2, + 4, 5" # for more complex node objects, you can specify # a node filter which will be used to extract the # information desired from each node $visitor->setNodeFilter(sub { my ($t) = @_; return $t->getNodeValue()->description(); }); DESCRIPTIONFor the most part, this class is just a wrapper around the Tree::Binary "traverse" method. METHODS
BUGSNone that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it. CODE COVERAGESee the CODE COVERAGE section of Tree::Binary for details. Repository<https://github.com/ronsavage/Tree-Binary> AUTHORstevan little, <stevan@iinteractive.com> COPYRIGHT AND LICENSECopyright 2004, 2005 by Infinity Interactive, Inc. <http://www.iinteractive.com> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|