Jun 25, 2009

Algorithm to find if a tree is symmetric?

Algorithm to find if a tree is symmetric?
(The tree is a generalized tree with as many child nodes as possible)
bool foo(tree* root1,tree* root2)
{
if(!root1&&!root2) return true;
if(!root1) return false;
if(!root2) return false;
if(root1->val!=root2_val) return false;
return foo(root1->left,root2->right)&&foo(root1->right,root2->left);
}

No comments:

Post a Comment