Java Reference
In-Depth Information
1. Print the left subtree of Juliet ; that is, Dick and descendants.
2. Print Juliet .
3. Print the right subtree of Juliet ; that is, Tom and descendants.
How do you print the subtree starting at Dick ?
1. Print the left subtree of Dick . There is nothing to print.
2. Print Dick .
3. Print the right subtree of Dick , that is, Harry .
That is, the left subtree of Juliet is printed as
Dick Harry
The right subtree of Juliet is the subtree starting at Tom . How is it printed? Again,
using the same algorithm:
1. Print the left subtree of Tom , that is, Romeo .
2. Print Tom .
3. Print the right subtree of Tom . There is nothing to print.
Thus, the right subtree of Juliet is printed as
Romeo Tom
731
732
Now put it all together: the left subtree, Juliet , and the right subtree:
Dick Harry Juliet Romeo Tom
The tree is printed in sorted order.
Let us implement the print method. You need a worker method printNodes of
the Node class:
private class Node
{
. . .
public void printNodes()
Search WWH ::




Custom Search