public class BinaryTree { private BinaryNode root; public BinaryTree( ) { root = null; } public BinaryTree(Object item) { this.root = new BinaryNode(item); } public BinaryTree(Object item, BinaryTree tleft, BinaryTree tright) { merge(item,tleft,tright); } public void merge( Object rootItem, BinaryTree t1, BinaryTree t2 ) { if( t1.root == t2.root && t1.root != null ) { System.err.println( "leftTree==rightTree; merge aborted" ); return; } // Allocate new node root = new BinaryNode( rootItem, t1.root, t2.root ); // Ensure that every node is in one tree if( this != t1 ) t1.root = null; if( this != t2 ) t2.root = null; } public boolean isEmpty() { return root == null; } public BinaryNode getRoot() { return root; } public void setRoot(BinaryNode root) { this.root=root; } public int getHeight() { return root.getHeight(); } public int getNodes() { return root.getNodes(); } public String toString() { return root.toString(); } public String toTree() { return root.toTree(); } public boolean naivefind(Object o) { return root.naivefind(o,root); } } // Class BinaryTree