Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started