// CSE 143, Winter 2011, Marty Stepp // A basic binary tree class that includes methods to construct a tree // of ints and to print its data. public class IntTree { private IntTreeNode overallRoot; // Constructs an empty binary tree (null root). public IntTree() { this(null); } // Constructs a binary tree with the given node as its root. public IntTree(IntTreeNode root) { overallRoot = root; } // Prints all elements of this tree in left-to-right order. public void print() { print(overallRoot); } // Recursive helper to print the given portion of the overall tree. private void print(IntTreeNode node) { // base case: null node, do nothing if (node != null) { // recursive case: non-null node, print it and its children // (works even if children are null, because then the recursive // call on the null child just fails the if test and does nothing) print(node.left); System.out.println(node.data); print(node.right); } } }