Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
public abstract class DupBinaryTree implements DupBinaryTreeADT { / / = = = = = = = = = = = = = = = =
public abstract class DupBinaryTree implements DupBinaryTreeADT Definition of the DupBinaryTreeNode class protected class DupBinaryTreeNode public T info; public DupBinaryTreeNode lLink; public DupBinaryTreeNode mLink; public DupBinaryTreeNode rLink; pts Default constructor public DupBinaryTreeNode this.info null; this.lLink null; this.mLink null; this.rLink null; pts Alternate constructor public DupBinaryTreeNodeT item, DupBinaryTreeNode left, DupBinaryTreeNode middle, DupBinaryTreeNode right this.info item; this.lLink left; this.mLink middle; this.rLink right; clone method public Object clone DupBinaryTreeNode copy null; try copy DupBinaryTreeNode super.clone; catch CloneNotSupportedException e return null; return copy; toString method public String toString return info.toString; End of class DupBinaryTreeNode Instance variable vor class DupBinaryTree protected DupBinaryTreeNode root; Default constructor public DupBinaryTree root null; public Object clone DupBinaryTree copy null; try copy DupBinaryTree super.clone; catch CloneNotSupportedException e return null; if root null copy.root copyTreeroot; return copy; Helper method called by clone private DupBinaryTreeNode copyTreeDupBinaryTreeNode otherTreeRoot DupBinaryTreeNode temp; if otherTreeRoot null temp null; else temp DupBinaryTreeNode otherTreeRoot.clone; temp.lLink copyTreeotherTreeRootlLink; temp.mLink copyTreeotherTreeRootmLink; temp.rLink copyTreeotherTreeRootrLink; return temp; Function to print the sorted tree without duplicates values Input: Nothing Output: The sorted tree without duplicates values public void printSortedTreeWithoutDuplicates printDistinctroot; TO BE IMPLEMENTED pts Function to print the sorted tree without duplicates values Input: DupBinaryTreeNode t : The current node in the tree Output: Nothing void public void printDistinctDupBinaryTreeNode t Function to print the sorted tree with duplicates values Input: Nothing Output: The sorted tree without duplicates values public void printSortedTreeWithDuplicates printDuproot; TO BE IMPLEMENTED pts Function to print the sorted tree with duplicates values Input: DupBinaryTreeNode t : The current node in the tree Output: Nothing void public void printDupDupBinaryTreeNode t
public abstract class DupBinaryTree implements DupBinaryTreeADT
Definition of the DupBinaryTreeNode class
protected class DupBinaryTreeNode
public T info;
public DupBinaryTreeNode lLink;
public DupBinaryTreeNode mLink;
public DupBinaryTreeNode rLink;
pts Default constructor
public DupBinaryTreeNode
this.info null;
this.lLink null;
this.mLink null;
this.rLink null;
pts Alternate constructor
public DupBinaryTreeNodeT item, DupBinaryTreeNode left, DupBinaryTreeNode middle, DupBinaryTreeNode right
this.info item;
this.lLink left;
this.mLink middle;
this.rLink right;
clone method
public Object clone
DupBinaryTreeNode copy null;
try
copy DupBinaryTreeNode super.clone;
catch CloneNotSupportedException e
return null;
return copy;
toString method
public String toString
return info.toString;
End of class DupBinaryTreeNode
Instance variable vor class DupBinaryTree
protected DupBinaryTreeNode root;
Default constructor
public DupBinaryTree
root null;
public Object clone
DupBinaryTree copy null;
try
copy DupBinaryTree super.clone;
catch CloneNotSupportedException e
return null;
if root null
copy.root copyTreeroot;
return copy;
Helper method called by clone
private DupBinaryTreeNode copyTreeDupBinaryTreeNode otherTreeRoot
DupBinaryTreeNode temp;
if otherTreeRoot null
temp null;
else
temp DupBinaryTreeNode otherTreeRoot.clone;
temp.lLink copyTreeotherTreeRootlLink;
temp.mLink copyTreeotherTreeRootmLink;
temp.rLink copyTreeotherTreeRootrLink;
return temp;
Function to print the sorted tree without duplicates values
Input: Nothing
Output: The sorted tree without duplicates values
public void printSortedTreeWithoutDuplicates
printDistinctroot;
TO BE IMPLEMENTED
pts
Function to print the sorted tree without duplicates values
Input: DupBinaryTreeNode t : The current node in the tree
Output: Nothing void
public void printDistinctDupBinaryTreeNode t
Function to print the sorted tree with duplicates values
Input: Nothing
Output: The sorted tree without duplicates values
public void printSortedTreeWithDuplicates
printDuproot;
TO BE IMPLEMENTED
pts
Function to print the sorted tree with duplicates values
Input: DupBinaryTreeNode t : The current node in the tree
Output: Nothing void
public void printDupDupBinaryTreeNode t
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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