/** Simple class for a binary tree; each node stores data of type E
 */
public class BinaryTree<E> {
	/** Root of the tree; null if the tree is empty
	 */
	protected BinaryTreeNode<E> root;

	public BinaryTree() {
		root = null;
	}

	/** Sets the root of the tree. 
	 * @param newRoot new value for root
	 */
	public void setRoot(BinaryTreeNode<E> newRoot) {
		root = newRoot;
	}

	public static void main(String[] args) {
		BinaryTree<Integer> tree = new BinaryTree<>();

		BinaryTreeNode<Integer> n5  = new BinaryTreeNode<>(5);
		BinaryTreeNode<Integer> n12 = new BinaryTreeNode<>(12);
		BinaryTreeNode<Integer> n22 = new BinaryTreeNode<>(22);
		BinaryTreeNode<Integer> n30 = new BinaryTreeNode<>(30);

		BinaryTreeNode<Integer> n9  = new BinaryTreeNode<>(9);
		n9.setLeft(n5);
		n9.setRight(n12);

		BinaryTreeNode<Integer> n24 = new BinaryTreeNode<>(24);
		n24.setLeft(n22);
		n24.setRight(n30);

		BinaryTreeNode<Integer> root = new BinaryTreeNode<>(18);
		root.setLeft(n9);
		root.setRight(n24);

		tree.setRoot(root);
	}
}
