6_36_相似二叉树

#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));
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2015-04-25 16:10  Thereisnospon  阅读(189)  评论(0编辑  收藏  举报