#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>
typedef struct BiTNode{
char data; //数据域
struct BiTNode *lchild,*rchild; //左右孩子指针
}BiTNode,*BiTree;
void CreateBiTree(BiTree &T){//递归创建二叉树。前序遍历算法的应用
char ch=getchar(); //输入当前结点的数据值
getchar(); //接受回车符
if(ch==' '){T=NULL; return;} //若输入空字符,则返回
else{
T=new BiTNode;
if (!T) exit(0);
T->data=ch;
cout<<"请输入"<<ch<<"的左孩子:"<<endl;
CreateBiTree(T->lchild);
cout<<"请输入"<<ch<<"的右孩子:"<<endl;
CreateBiTree(T->rchild);
}
}
void PreOrder(BiTree root){//递归前序遍历
if(root)
{cout<<root->data;
PreOrder(root->lchild);
PreOrder(root->rchild);
}
}
void InOrder(BiTree root){//递归中序遍历
if(root)
{
InOrder(root->lchild);
cout<<root->data;
InOrder(root->rchild);
}
}
void PostOrder(BiTree root){//递归后序遍历
if(root)
{
PostOrder(root->lchild);
PostOrder(root->rchild);
cout<<root->data;
}
}
//中序遍历非递归算法
void InOrder1(BiTree T){
int i=0;
BiTree p=T, s[10];