// This class represents a tree of integers public class IntTree { private IntTreeNode overallRoot; // Constructs a tree with default numbers public IntTree() { // overallRoot = null; IntTreeNode overall = new IntTreeNode(17); overallRoot.left = new IntTreeNode(41); overallRoot.right = new IntTreeNode(9); overallRoot.left.left = new IntTreeNode(29); overallRoot.left.right = new IntTreeNode(6); overallRoot.right.left = new IntTreeNode(81); overallRoot.right.right = new IntTreeNode(40); } // prints the numbers in this tree in a pre-order fashion. public void print() { print(overallRoot); } // prints the numbers of the subtree rooted at root // using a pre-order traversal. private void print(IntTreeNode root) { if (root != null) { System.out.print(root.data + " "); // print the left print(root.left); // print the right print(root.right); } } // Returns true if n is in this tree, false otherwise. public boolean contains(int n) { return contains(overallRoot, n); } // Returns true if n appears as the data for a node in the sub-tree rooted // at root. Returns false if the tree is empty. private boolean contains(IntTreeNode root, int n) { if (root == null) { return false; } else if (root.data == n) { return true; } else { return contains(root.left, n) || contains(root.right, n); } } }