#include<stdio.h>
#include<malloc.h>
typedef char ElenType;
typedef struct BitNode{
char data;
struct BitNode *lChild;
struct BitNode *rChild;
}BitNode,*BitTree;
//创建一颗二叉树,前序遍历输入数据
createBitTree(BitTree *T){
char c;
scanf("%c",&c);
if(' ' == c){
*T = NULL;
}
else{
*T = (BitNode *)malloc(sizeof(BitNode));
(*T)->data = c;
createBitTree(&(*T)->lChild);
createBitTree(&(*T)->lChild);
}
}
visit(char c,int level){
printf("%c位于%d层\n",c,level);
}
//遍历二叉树,前序遍历
preOrderTraversal(BitTree T,int leveal){
if(T){
visit(T->data,leveal);
preOrderTraversal(T->lChild,leveal+1);
preOrderTraversal(T->rChild,leveal+1);
}
}
void main(void){
int leveal = 0;
BitTree T = NULL;
createBitTree(&T);
preOrderTraversal(T,leveal);
}