/*
二叉树扩展先序输入转中序遍历
样例输入
abc##de#g##f###
样例输出
c b e g d f a
样例说明
根据给定的扩展先序遍历序列,建立对应的二叉树,然后对所得的二叉树进行中序遍历输出结果即可。
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct BTnode{
char data;
struct BTnode* pLchild;
struct BTnode* pRchild;
}BTNODE,*PBTNODE;
void CreateBTree(PBTNODE*);
void Intraverse(PBTNODE);
int main(int argc, const char * argv[]) {
PBTNODE T;
CreateBTree(T);
Intraverse(T);
return 0;
}
void CreateBTree(PBTNODE *t){
char ch;
scanf("%c",&ch);
if(ch=='#') t=NULL;
else{
*t=(PBTNODE)malloc(sizeof(BTNODE));
(*t)->data=ch;//生成根节点
CreateBTree(&(*t)->pRchild);//生成左子树
CreateBTree(&(*t)->pLchild);//生成右子树
}
}
void Intraverse(PBTNODE t){
if(t==NULL) return;
Intraverse(t->pLchild);
printf("%c",t->data);
Intraverse(t->pRchild);
}