// CSE 143, Winter 2009, Marty Stepp // // This client program creates a tree of integers and prints its elements. // You can see a nice visualization of binary trees in jGRASP's debugger. // // Output: // 29 41 6 42 81 9 40 // // 42 41 29 6 9 81 40 // 29 6 41 81 40 9 42 public class TreeMain { public static void main(String[] args) { // construct a tree, manually, node by node (tedious; not standard) IntTreeNode root = new IntTreeNode(42); root.left = new IntTreeNode(41); root.right = new IntTreeNode(9); root.left.left = new IntTreeNode(29); root.left.right = new IntTreeNode(6); root.right.left = new IntTreeNode(81); root.right.right = new IntTreeNode(40); // print the elements of the tree using IntTree class IntTree tree = new IntTree(root); tree.print(); // a second, empty tree IntTree tree2 = new IntTree(); tree2.print(); // pre-order and post-order traversals of a tree tree.printPreOrder(); tree.printPostOrder(); } }