📄 iseqbitr.c
字号:
#include<stdio.h>
#include<stdlib.h>
typedef char datatype;
typedef struct node /*二叉树结点定义*/
{
datatype data;
struct node *lchild,*rchild;
}bintnode;
typedef bintnode *bintree;
void createbintree(bintree *t)
{/*按照前序遍历的顺序建立一棵给定的二叉树*/
char ch;
if ((ch=getchar())==' ')
*t=NULL;
else {
*t=(bintnode *)malloc(sizeof(bintnode));
(*t)->data=ch;
createbintree(&(*t)->lchild);
createbintree(&(*t)->rchild);
}
}
int isequal(bintree t1,bintree t2)
{ /*判断二叉树t1和t2是否等价*/
int t;
t=0;
if (t1==NULL && t2==NULL) t=1; /*t1和t2均为空,则二者等价*/
else
if (t1!=NULL && t2!=NULL) /*处理t1和t2均不为空的情形*/
if (t1->data==t2->data) /*如果根结点的值相等*/
if (isequal(t1->lchild,t2->lchild)) /*如果t1和t2的左子树等价*/
t=isequal(t1->rchild,t2->rchild); /*返回值取决于t1和t2的右子树是否等价的结果*/
return(t);
}
main()
{ bintree root1,root2;
int equal;
createbintree(&root1);getchar();
createbintree(&root2);getchar();
equal=isequal(root1,root2) ;
if (equal) printf("equal!");
else printf("is't equal!") ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -