Tree::Binary2(3pm) User Contributed Perl Documentation Tree::Binary2(3pm)

Tree::Binary2 - An implementation of a binary tree

  my $tree = Tree::Binary2->new( 'root' );
  my $left = Tree::Binary2->new( 'left' );
  $tree->left( $left );
  my $right = Tree::Binary2->new( 'left' );
  $tree->right( $right );
  my $right_child = $tree->right;
  $tree->right( undef ); # Unset the right child.
  my @nodes = $tree->traverse( $tree->POST_ORDER );
  my $traversal = $tree->traverse( $tree->IN_ORDER );
  while ( my $node = $traversal->() ) {
      # Do something with $node here
  }

This is an implementation of a binary tree. This class inherits from Tree, which is an N-ary tree implemenation. Because of this, this class actually provides an implementation of a complete binary tree vs. a sparse binary tree. The empty nodes are instances of Tree::Null, which is described in Tree. This should have no effect on your usage of this class.

In addition to the methods provided by Tree, the following items are provided or overriden.

In-order

This will return the result of an in-order traversal on the left node (if any), then the node, then the result of an in-order traversal on the right node (if any).

NOTE: You have access to all the methods provided by Tree, but it is not recommended that you use many of them, unless you know what you're doing. This list includes add_child() and remove_child().

Please see the relevant sections of Tree.

Please see the relevant sections of Tree.

Rob Kinyon <rob.kinyon@iinteractive.com>

Stevan Little <stevan.little@iinteractive.com>

Thanks to Infinity Interactive for generously donating our time.

Copyright 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.

2024-02-17 perl v5.38.2