你确定你的序列没写错?
先序创建一颗二叉树遍历;
#include
#include
#include
#define OVERFLOW -2
#define OK 1
#define ERROR 0
typedef int status;
typedef char TElemtype;
typedef struct BiTNode{
TElemtype data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
status Visit(TElemtype e)
{
printf(" %c ",e);
return OK;
}
void InoRtraverse(BiTree T,status(* Visit)(TElemtype)){
if(T){
InoRtraverse(T->lchild,Visit);
Visit(T->data);
InoRtraverse(T->rchild,Visit);
}
}
void PosTtraverse(BiTree T,status(* Visit)(TElemtype)){
if(T){
PosTtraverse(T->lchild,Visit);
PosTtraverse(T->rchild,Visit);
Visit(T->data);
}
}
status creatBiTree(BiTree *T){
char c;
scanf("%c",&c);
if(c==' ')
(*T)=NULL;
else{
if(!((*T)=(BiTNode *)malloc(sizeof(BiTNode))))
exit(OVERFLOW);
(*T)->data=c;
creatBiTree(&((*T)->lchild));
creatBiTree(&((*T)->rchild));
}
return OK;
}
void main(){
BiTree T;
creatBiTree(&T);
printf("\n按照中序排列输出\n");
InoRtraverse(T,Visit);
printf("\n按照后序排列输出\n");
PosTtraverse(T,Visit);
}