二叉树中储存的数据范围仅限于26个英文字母
程序提示用户输入二叉树的先序和中序序列
接受输入后,调用相应函数完成二叉树的创建
成功创建后:程序自动输出该二叉树的后续遍历序列
~~~~~~
试了很多都不行,
那位高手能帮一下?
以下是我自己写的:
没有错误,可是在输入时就有问题
#include <stdio.h>
#include <stdlib.h>
typedef struct BTree{
char data;
struct BTree *lchild;
struct BTree *rchild;
}BinTree;
BinTree *pre_order(BinTree *p)
{
char ch;
if(p!=NULL)
{
scanf("%c",&ch);
if(ch==' ')
return NULL;
else
{
p=(BinTree *)malloc(sizeof(BinTree));
p->data=ch;
pre_order(p->lchild);
pre_order(p->rchild);
return p;
}
}
}
BinTree *in_order(BinTree *p)
{
char ch;
if(p)
{
in_order(p->lchild);
scanf("%c",&ch);
if(ch==' ')
return NULL;
in_order(p->rchild);
}
}
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(&tree);
printf("\n");
printf("Please Enter the in_order:\n");
in_order(&tree);
printf("\n");
post_order(&tree);
printf("\n");
}