I wrote a method that checks if two binary tree are equal.
Is this correct or is there a better way?
public boolean equal(BinaryNode t1, BinaryNode t2){
if(t1==null || t2==null)
return false;
else if(t1.element != t2.element)
return false;
else if(equal(t1.left,t2.left))
return false;
else if(equal(t1.right,t2.right))
return false;
else
return true;
}
The following is probably closer to the logic you’re looking for, but is completely untested and was written in this text field:
There are a lot of flaws in your current version.