递归判断两棵树是否相似

bool IsSemblable2(BiTree T1,BiTree T2)
{
bool leftS = false,rightS = false; //用来接受子树返回的信息,此步骤可不写
if(T1 == NULL && T2 == NULL) // 两个结点都为空
{return true; } //两节点多为空的时候,执行返回T
else if(T1 == NULL || T2 == NULL) //之前已经判断过两节点不可能多为空,那么有一个结点不为空
{ return false; } //若有节点为空,返回F
else
{
int leftS = IsSemblable2(T1->lchild,T2->lchild); //递归左子树,接受子树返回的信息
int rightS = IsSemblable2(T1->rchild,T2->rchild); //递归右子树,接受子树返回的信息
return leftS && rightS ; //向上一级返回两个子树的信息,如果左右子树有一个不符合相似,那么返回F
}
}

        &&一假全假,||一真全真。  


             判断两棵树是否相似 树形一样 数值不一样 

bool IsSimilar(BTNode *t1,BTNode *t2){
if(t1==null && t2==null) return true;
if(t1==null || t2==null) return false;
else{
return IsSimilar(t1->lchild,t2->lchild) &&
IsSimilar(t1->rchild,t2->rchild);
}
}

                   判断该两棵树是否相等 

bool IsEqual(BTNode *t1,BTNode *t2)
{
if(t1==null && t2==null)
return true;
if(t1==null || t2==null)
return false;
if(t1->data==t2->data) //判断数值是否相同
{
return IsEqual(t1->lchild,t2->lchild) &&IsEqual(t1->rchild,t2->rchild) //层层递归,并判断数值是否相同
}
else
{
return false;
}
}