#include<stdio.h>
#include<stdlib.h>
#define depth 5
typedef int Status;
typedef char TElemtype;
typedef struct BiTNode{
TElemtype data;
struct BiTNode *lchild,*rchild;
}*BiTree;
Status printElement(TElemtype e){
printf("%c",e);
return 1;
}
Status InitBTree(BiTree &T)
{
T = NULL;
return 1;
}
char* CreatBiTree(BiTree &T,char *s){
if((*s)==‘ ‘){
T=NULL;
return s+1;
}
else{
T=(BiTNode * )malloc(sizeof(BiTNode));
if(!T) return 0;
T->data=(*s);
CreatBiTree(T->rchild,CreatBiTree(T->lchild,s+1));
}
}
//先序遍历
Status PreOrderTraverse(BiTree T,Status(* Visit)(TElemtype e)){
if(T){
Visit(T->data);
PreOrderTraverse(T->lchild,Visit);
PreOrderTraverse(T->rchild,Visit);
}
return 1;
}
//后序
Status PostOrderTraverse(BiTree T,Status(* Visit)(TElemtype e)){
if(T){
PostOrderTraverse(T->lchild,Visit);
PostOrderTraverse(T->rchild,Visit);
Visit(T->data);
}
return 1;
}
//中序
Status InOrderTraverse(BiTree T,Status(* Visit)(TElemtype e)){
if(T){
InOrderTraverse(T->lchild,Visit);
Visit(T->data);
InOrderTraverse(T->rchild,Visit);
}
return 1;
}
int main(){
BiTree t;
char a[100]={"ABC DE G F "};
InitBTree(t);
CreatBiTree(t,a);
PreOrderTraverse(t,printElement);
printf("\n");
PostOrderTraverse(t,printElement);
printf("\n");
InOrderTraverse(t,printElement);
printf("\n");
return 0;
}