#include<stdio.h>
#include<stdlib.h>
typedef struct BitNode{
char data;
struct BitNode *lchild,*rchild;
} *BiTree;
int CreateBiTree(BiTree &T){
char ch;
//char ch1;
ch =getchar();
//ch =ch1;
if(ch == '#' )
T =NULL;
else
{
if(!(T = (BitNode*)malloc(sizeof(BitNode)))) exit(0);
T->data = ch;//生成根结点;
CreateBiTree(T->lchild);//构造左子树
CreateBiTree(T->rchild);//构造右子树
}
return 1;
}
int PreOrderTraverse(BiTree T){
if(T){
printf("%c",T->data);
PreOrderTraverse(T->lchild);
PreOrderTraverse(T->rchild);
}
else
return 0;
}
void InOrderTraverse(BiTree T){
if(T){
InOrderTraverse(T->lchild);
printf("%c",T->data);
InOrderTraverse(T->rchild);
}
}
void PostOrderTraverse(BiTree T){
if(T){
PostOrderTraverse(T->lchild);//后序遍历 最左边当结点左右子树到为空时候打印
PostOrderTraverse(T->rchild);
printf("%c",T->data);
}
}
int main(){
BiTree T;
CreateBiTree(T);
printf("\prenordertraverse ");
PreOrderTraverse(T);
printf("\npostordertraverse ");
PostOrderTraverse(T);
printf("\ninordertraverse ");
InOrderTraverse(T);
return 0;
}