typedef char TElemType;
//结点数据结构
{
TElemType data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
//先序遍历
{
if(T == NULL)
return;
printf("%c",T->data);
PreOrderTraverse(T->lchild);
PreOrderTraverse(T->rchild);
}
//中序遍历
{
if(T == NULL)
return;
InOrderTraverse(T->lchild);
printf("%c",T->data);
InOrderTraverse(T->rchild);
}
//后序遍历
{
if(T == NULL)
return;
PostOrderTraverse(T->lchild);
PostOrderTraverse(T->rchild);
printf("%c",T->data);
}
//创建树
void CreateBiTree(BiTree *T)
{
TElemType ch;
ch = getchar();
char ch2 = getchar(); //delete enter key
if(ch == '#')
{
*T = NULL;
return;
}
else
{
*T = (BiTree)malloc(sizeof(BiTNode));
if(!*T)
{
printf("error");
return;
}
(*T)->data = ch;
CreateBiTree(&(*T)->lchild);
CreateBiTree(&(*T)->rchild);
}
}
void test()
{
BiTree T;
T= (BiTree)malloc(sizeof(BiTNode));
CreateBiTree(&T);
PreOrderTraverse(T);
}