Answer:
public boolean equals(Object other)
{
// check correct instance
if (other instanceof IntTree)
{
try
{
IntTree otherTree = (IntTree) other;
return equals(overallRoot, otherTree.overallRoot);
}
// caught exceptions
catch (Exception e)
{
return false;
}
}
return false;
}
public boolean equals(IntTreeNode tree1, IntTreeNode tree2)
{
// if reach ends
if (tree1 == null && tree2 == null)
{
// they are equal
return true;
}
else if (tree1 == null || tree2 == null)
{
// not equal
return false;
}
// check left part
boolean leftPart = equals(tree1.left, tree2.left);
// check current element is same
boolean currentPart = tree1.element.equals(tree2.element);
// check right part
boolean rightPart = equals(tree1.right, tree2.right);
// all are equal
return (leftPart && currentPart && rightPart);
}
Step-by-step explanation: