Java Reference
In-Depth Information
entire program in one file, BinaryTreeTest.java , you can omit the word public and include the classes TreeNode and
BinaryTree in the positions indicated in Program P8.1.
Program P8.1
import java.io.*;
import java.util.*;
public class BinaryTreeTest {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(new FileReader("btree.in"));
BinaryTree bt = new BinaryTree(in);
System.out.printf("\nThe pre-order traversal is: ");
bt.preOrder();
System.out.printf("\n\nThe in-order traversal is: ");
bt.inOrder();
System.out.printf("\n\nThe post-order traversal is: ");
bt.postOrder();
System.out.printf("\n\n");
in.close();
} // end main
} //end class BinaryTreeTest
class NodeData {
String word;
public NodeData(String w) {
word = w;
}
public void visit() {
System.out.printf("%s ", word);
}
} //end class NodeData
// class TreeNode goes here
// class BinaryTree goes here
If btree.in contains C E F @ H @ @ B @ @ G A @ @ N J @ @ K @ @ , then Program P8.1 builds the
following tree:
C
G
E
N
F
B
A
J
K
H
Search WWH ::




Custom Search