编译通过
先序创建并输出
#include
#include
typedef struct BTree{
char data;
struct BTree *lchild;
struct BTree *rchild;
}BinTree;
BinTree *pre_order()
{
BinTree *p;
char ch;
scanf("%c",&ch);
if(ch==' ')
return NULL;
p=(BinTree *)malloc(sizeof(BinTree));
p->data=ch;
p->lchild=pre_order();
p->rchild=pre_order();
return p;
}
BinTree *in_order()
{
BinTree *p;
char ch;
p->lchild=in_order();
scanf("%c",&ch);
if(ch==' ')
return NULL;
p->rchild=in_order();
}
void post_order(BinTree *p)
{
if(p!=NULL)
{
post_order(p->lchild);
post_order(p->rchild);
printf("%c ",p->data);
}
}
void main()
{
BinTree *tree;
printf("Please Enter the pre_order:\n");
tree=pre_order();
printf("\n");
//printf("Please Enter the in_order:\n");
//tree=in_order();
//printf("\n");
post_order(tree);
printf("\n");
}
先序和中序不能同时使用,要么就光先序,要么就再用另一个数做中序
BinTree *in_order(BinTree *p)
{
char ch;
if(p)
{
in_order(p->lchild);
scanf("%c",&ch);
if(ch==' ')
return NULL;
in_order(p->rchild);
}
}
好象不能创建吧???