Binary Tree operator overloading and recursion
- by furious.snail
I was wondering how to overload the == operator for a binary tree to compare if two trees have identical data at same nodes. So far this is what I have:
bool TreeType::operator==(const TreeType& otherTree) const
{
if((root == NULL) && (otherTree.root == NULL))
return true; //two null trees are equal
else if((root != NULL) && (otherTree.root != NULL))
{
return((root-info == otherTree.root-info) &&
//this part doesn't actually do anything recursively...
//(root-left == otherTree.root-left) &&
//(root-right == otherTree.root-right))
}
else
return false; //one tree is null the other is not
}
I have a similar function that takes two TreeNode pointers as parameters but I've been stuck on how to convert it to this function.