二叉树创建那有点小问题,能不能帮忙改下
程序代码:#include <stdio.h>
#include<stdlib.h>
#define MAXSIZE 100
typedef struct BiTreeNode
{
char data;
struct BiTreeNode *lchild,*rchild;
}BTNode;
BTNode *Create_BiTree()//二叉树的建立
{//用辅助数组建立二叉树
int i,j;
char ch;
BTNode *s,*t,*p[MAXSIZE];
printf("输入顶点编号i及信息ch,输入0和#结束:i,ch \n");
scanf("%d,%c",&i,&ch);
while(i==0||ch=='#') break;
while(i!=0&&ch!='#'){ //建立二叉树的存储结构
s=(BTNode *)malloc(sizeof(BTNode));
s->data=ch;
s->lchild=s->rchild=NULL;
p[i]=s;
if(i==1) t=s;//判断输入结点是根结点、左孩子还是右孩子
else
{j=i/2;
if(i%2==0) p[j]->lchild=s;
else p[j]->rchild=s;
}
}
return t;
}// Create_BiTree
void Preorder(BTNode *bt)
{//前序递归遍历
if(bt)
{
printf("%c",bt->data);
Preorder(bt->lchild);
Preorder(bt->rchild);
}
}/* Preorder*/
void Inorder(BTNode *bt){//中序递归遍历
if(bt)
{
Inorder(bt->lchild);
printf("%c",bt->data);
Inorder(bt->rchild);
}
}//Inorder
void Postorder(BTNode *bt){//后序递归遍历
if(bt)
{
Postorder(bt->lchild);
Postorder(bt->rchild);
printf("%c",bt->data);
}
}//Postorder
main()
{
int j=1;
BTNode *T;
T=Create_BiTree();
while(j)
{
printf("\n"); //功能菜单
printf("请选择操作:\n");
printf("1: 二叉树的前序遍历\n");
printf("2: 二叉树的中序遍历\n");
printf("3: 二叉树的后序遍历\n");
printf("0: 退出程序\n");
scanf("%d",&j);
if(j<0||j>3)
printf("你的输入有误,请重新选择!\n");
switch(j)
{
case 0: printf(" 程序退出!\n ");break;
case 1: printf("前序遍历结果:\n"); Preorder(T); break;
case 2: printf("中序遍历结果:\n"); Inorder(T);break;
case 3: printf("后序遍历结果:\n"); Postorder(T);break;
default : printf("\n输入无效,请重新选择操作!\n" );break;
}
}
}
以二叉链表作存储结构的二叉树,然后按先序、中序、后序顺序分别遍历这棵二叉树









