Question: Please complete the following comments that ask to add code public class BinaryTree implements BinaryTreeInterface { private BinaryNode root; public BinaryTree ( ) { root

Please complete the following comments that ask to add code
public class BinaryTree implements BinaryTreeInterface
{
private BinaryNode root;
public BinaryTree()
{
root = null;
}// end default constructor
public BinaryTree(T rootData)
{
this.root = new BinaryNode<>(rootData);
}// end constructor
public BinaryTree(T rootData, BinaryTree leftTree, BinaryTree rightTree)
{
initializeTree(rootData, leftTree, rightTree);
}// end constructor
public void setTree(T rootData, BinaryTree leftTree, BinaryTree rightTree)
{
initializeTree(rootData, leftTree, rightTree);
}// end setTree
public void setRootData(T rootData)
{
root.setData(rootData);
}// end setRootData
public T getRootData()
{
if (isEmpty())
throw new EmptyTreeException();
else
return root.getData();
}// end getRootData
public boolean isEmpty()
{
return root == null;
}// end isEmpty
public void clear()
{
root = null;
}// end clear
public int getHeight()
{
int height =0;
if (root != null)
/* Add code to getHeight method */
return height;
}// end getHeight
public int getNumberOfNodes()
{
int numberOfNodes =0;
if (root != null)
/* Add code to getNumberOfNodes method */
return numberOfNodes;
}// end getNumberOfNodes
protected void setRootNode(BinaryNode rootNode)
{
root = rootNode;
}// end setRootNode
protected BinaryNode getRootNode()
{
return root;
}// end getRootNode
private void initializeTree(T rootData, BinaryTree leftTree, BinaryTree rightTree)
{
root = new BinaryNode<>(rootData);
/* Add code check if left subtree exits and with node */
if ()
root.setLeftChild(leftTree.root);
if ((rightTree != null) && !rightTree.isEmpty())
{
/* Add code check if right subtree not equal to left subTree */
if ()
root.setRightChild(rightTree.root);
else
/* Add code to root.setRightChild with copy() method */
}// end if
/* Add code to check if leftTree subTree exist and leftTree subTree not equal to itself */
if ()
leftTree.clear();
/* Add code to check if rightTree subTree exist and rightTree subTree not equal to itself */
if ()
rightTree.clear();
}// end initializeTree

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!