2: /** Copies the subtree rooted at this node. 3: @return The root of a copy of the subtree rooted at this node. 4: @author Frank M. Carrano, Timothy M. Henry 5: @version 5.0 */ 6: public BinaryNode<T> copy() 7: { 8: BinaryNode<T> newRoot = new BinaryNode<>(data); 9: if (leftChild != null) 10: newRoot.setLeftChild(leftChild.copy()); 12: if (rightChild != null) 13: newRoot.setRightChild(rightChild.copy()); 15: return newRoot; 16: } // end copy 18: private void initializeTree(T rootData, BinaryTree<T> leftTree, BinaryTree<T> rightTree) 19: { 20: root = new BinaryNode<>(rootData); 21: if ((leftTree != null) && !leftTree.isEmpty()) 22: root.setLeftChild(leftTree.root.copy()); 23: if ((rightTree != null) && !rightTree.isEmpty()) 24: root.setRightChild(rightTree.root.copy()); 25: } // end initializeTree