Java Reference
In-Depth Information
{
if (left != null)
left.printNodes();
System.out.print(data + " ");
if (right != null)
right.printNodes();
}
. . .
}
To print the entire tree, start this recursive printing process at the root, with the
following method of the BinarySearchTree class.
public class BinarySearchTree
{
. . .
public void print()
{
if (root != null)
root.printNodes();
System.out.println();
}
. . .
}
This visitation scheme is called inorder traversal. There are two other traversal
schemes, called preorder traversal and postorder traversal.
Tree traversal schemes include preorder traversal, inorder traversal, and postorder
traversal.
In preorder traversal,
ȗ Visit the root
ȗ Visit the left subtree
ȗ Visit the right subtree
In postorder traversal,
ȗ Visit the left subtree
Search WWH ::




Custom Search