标签:
int CompTree(TreeNode *tree1, TreeNode *tree2)
{
bool isTree1Null = (tree1 == NULL);
bool isTree2Null = (tree2 == NULL);
//其中一个为NULL,而另一个不为NULL,肯定不相等
if (isTree1Null != isTree2Null)
return 1;
//两个都为NULL,一定相等
if (isTree1Null && isTree2Null)
return 0;
//两个都不为NULL,如果c不等,则一定不相等
if (tree1->c != tree2->c)
return 1;
//两个都不为NULL,且c相等,则看两棵子树是否相等或者是否互换相等
return (CompTree(tree1->left, tree2->left)&CompTree(tree1->right, tree2->right))|
(CompTree(tree1->left, tree2->right)&CompTree(tree1->right, tree2->left));
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/wangfengfan1/article/details/47264173