public class IntTree { private class IntTreeNode { public final int data; public IntTreeNode left; public IntTreeNode right; public IntTreeNode(int data, IntTreeNode left, IntTreeNode right) { this.data = data; this.left = left; this.right = right; } public IntTreeNode(int data) { this(data, null, null); } } private IntTreeNode root; /* VERY BAD */ public IntTree() { this.root = new IntTreeNode(0, new IntTreeNode(1, new IntTreeNode(2), new IntTreeNode(3) ), new IntTreeNode(4) ); } public void print() { this.print(this.root); } private void print(IntTreeNode current) { if (current != null) { System.out.print(current.data + " "); this.print(current.left); this.print(current.right); } } public boolean contains(int value) { return this.contains(this.root, value); } private boolean contains(IntTreeNode current, int value) { if (current == null) { return false; } else if (current.data == value) { return true; } else { /* check the rest */ return this.contains(current.left, value) || this.contains(current.left, value); } } }