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 BinaryTreeT rootData
this.root new BinaryNoderootData;
end constructor
public BinaryTreeT rootData, BinaryTree leftTree, BinaryTree rightTree
initializeTreerootData leftTree, rightTree;
end constructor
public void setTreeT rootData, BinaryTree leftTree, BinaryTree rightTree
initializeTreerootData leftTree, rightTree;
end setTree
public void setRootDataT rootData
root.setDatarootData;
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 ;
if root null
Add code to getHeight method
return height;
end getHeight
public int getNumberOfNodes
int numberOfNodes ;
if root null
Add code to getNumberOfNodes method
return numberOfNodes;
end getNumberOfNodes
protected void setRootNodeBinaryNode rootNode
root rootNode;
end setRootNode
protected BinaryNode getRootNode
return root;
end getRootNode
private void initializeTreeT rootData, BinaryTree leftTree, BinaryTree rightTree
root new BinaryNoderootData;
Add code check if left subtree exits and with node
if
root.setLeftChildleftTreeroot;
if rightTree null && rightTree.isEmpty
Add code check if right subtree not equal to left subTree
if
root.setRightChildrightTreeroot;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
