/* * Kyle Pierce * CSE 143 * * This class represents a binary tree of integers */ public class IntTree { private IntTreeNode overallRoot; // post: constructs an empty tree public IntTree() { overallRoot = null; } // post: prints the tree contents using a preorder traversal public void printPreorder() { System.out.print("preorder:"); printPreorder(overallRoot); System.out.println(); } // post: prints in preorder the tree with given root private void printPreorder(IntTreeNode root) { if (root != null) { System.out.print(" " + root.data); printPreorder(root.left); printPreorder(root.right); } } // post: prints the tree contents using an inorder traversal public void printInorder() { System.out.print("inorder:"); printInorder(overallRoot); System.out.println(); } // post: prints in inorder the tree with given root private void printInorder(IntTreeNode root) { if (root != null) { printInorder(root.left); System.out.print(" " + root.data); printInorder(root.right); } } // post: prints the tree contents using a postorder traversal public void printPostorder() { System.out.print("postorder:"); printPostorder(overallRoot); System.out.println(); } // post: prints in postorder the tree with given root private void printPostorder(IntTreeNode root) { if (root != null) { printPostorder(root.left); printPostorder(root.right); System.out.print(" " + root.data); } } }