Firstly, I am not familiar with the class
BinaryNode
so I would guess it is your own.
The approach I would take is to make the class implement the
equals
method:
public class BinaryNode {
public int equals(Object obj) {
if (this == obj) {
return true;
}
if ( obj == null || !(obj instanceof BinaryNode)) {
return false;
}
BinaryNode that = (BinaryNode)obj;
if (this.element.equals(that.element)) {
return false;
}
else if (this.left == null || this.left.equals(that.left)) {
return false;
}
else if (this.right == null || this.right.equal(that.right)) {
return false;
}
return true;
}
}