public class IntTree { private IntTreeNode root; /* IntTreeNode has (1) data, (2) left, (3) right */ public IntTree() { this.root = new IntTreeNode(0, new IntTreeNode(1, new IntTreeNode(2), null), new IntTreeNode(3, null, new IntTreeNode(4))); } public boolean contains(int value) { return contains(this.root, value); } private boolean contains(IntTreeNode current, int value) { if (current == null) { return false; } else if (current.data == value) { return true; } else { // current.left boolean containedLeft = contains(current.left, value); // current.right boolean containedRight = contains(current.right, value); return containedLeft || containedRight; } } public void print() { print(this.root); } private void print(IntTreeNode current) { if (current != null) { System.out.print(current.data + " "); print(current.left); print(current.right); } } } // [0] -> ([1] -> [2]) // print root