#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct node
{
int data;
struct node*lchild,*rchild;
}tnode,*tree;
tree creat()
{
int x;
tree t;
scanf("%d",&x);
if(x==0)t=NULL;
else
{
t=(tnode*)malloc(sizeof(tnode));
t->data=x;
t->lchild=creat();
t->rchild=creat();
}
return t;
}
void preorder(tree t)
{
if(t)
{
printf("%d ",t->data);
preorder(t->lchild);
preorder(t->rchild);
}
}
int IfLike(tree a,tree b)
{
if(!a&&!b)
return 1;
else if(a&&b)
return (IfLike(a->lchild,b->lchild)&&IfLike(a->rchild,b->rchild));
else return 0;
}
int main()
{
tree a=creat();
tree b=creat();
printf("%d\n",IfLike(a,b));
}
6_36_相似二叉树
最新推荐文章于 2021-07-26 15:32:16 发布