#include <stdio.h>
#include <stdlib.h>
typedef struct BiTNode{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
void CreateBiTree(BiTree *T){
char c;
scanf("%c",&c);
if(c==' '){
*T=NULL;
}
else{
*T=(BiTree *)malloc(sizeof(BiTNode));
(*T)->data=c;
CreateBiTree(&(*T)->lchild);
CreateBiTree(&(*T)->rchild);
}
}
void PreOrderTraverse(BiTree T,int level){
if(T){
printf("第%d层的数据:%c",level,T->data);
PreOrderTraverse(T->lchild,level+1);
PreOrderTraverse(T->rchild,level+1);
}
}
int main(){
BiTree T=NULL;
int level=1;
CreateBiTree(&T);
PreOrderTraverse(T,level);
return 0;
}