#include <stdio.h>
typedef struct BiTNode{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
CreateBiTree(BiTree *T)
{
char c;
scanf(“%c”,&c);
if(‘ ‘ == c)
{
*T = NULL;
}
else
{
*T = (BiTNode *)malloc(sizeof(BiTNode));
(*T)->data = c;
CreateBiTree(&(*T)->lchild);
CreateBiTree(&(*T)->rchild);
}
}
visit(char c,int level)
{
printf(“%c位于第几%d层\n”,c,level);
}
PreOrederTraverse(BiTree T,int level)
{
if(T)
{
visit(T->data,level);
PreOrederTraverse(T->lchild,level+1);
PreOrederTraverse(T->rchild,level+1);
}
}
void main(){
int level=1;
BiTree *T = NULL;
CreateBiTree(&T);
PreOrederTraverse(T,level);
}