#include<stdio.h>
#include<stdlib.h>
typedef struct tree
{char data;
struct tree *leftchild;
struct tree *rightchild;
}bt,*btree;
btree creat()
{btree T;
char ch;
scanf("%c",&ch);
if(ch=='#')
{T=NULL;}
else
{T=(btree)malloc(sizeof(bt));
T->data=ch;
T->leftchild=creat();
T->rightchild=creat();
}
return T;
}
void firsttraver(btree T)
{if(T)
{printf("%c",T->data);
firsttraver(T->leftchild);
firsttraver(T->rightchild);
}
}
int main()
{btree p;
p=creat();
firsttraver(p);
printf("\n");
return 0;
}
二叉树的建立
最新推荐文章于 2021-05-19 10:03:51 发布