二叉链表的建立出错
在中序遍历函数的这一步ptr=ptr->lch;开始就执行不下去了是不是二叉链表没有建立起来
程序代码:#include <stdio.h>
#include <malloc.h>
#define N 10
struct node
{
int data;
struct node *lch;
struct node *rch;
};
typedef struct node bitree;
bitree *prec_bt(bitree *bt)
{
int a;
printf("请输入结点的值:\n");
scanf("%d",&a);
if(a==0)
{
bt=(bitree *)malloc(sizeof(bitree));
bt=NULL;
}
else
{
bt=(bitree *)malloc(sizeof(bitree));
bt->data=a;
prec_bt(bt->lch);
prec_bt(bt->rch);
}
return bt;
}
bitree *In_bt(bitree *root)
{
bitree *Ss[N];
bitree *ptr;
int Ss_top=-1;
ptr=prec_bt(root);
printf("二叉树各结点的值为:\n");
while((ptr!=NULL)||(Ss_top!=-1))
{
while(ptr!=NULL)
{
Ss_top++;
Ss[Ss_top]=ptr;
ptr=ptr->lch;
}
if(Ss_top!=-1)
{
ptr=Ss[Ss_top];
printf("%d",ptr->data);
Ss_top--;
ptr=ptr->rch;
}
}
printf("over");
return root;
}
main()
{
bitree *root;
In_bt(root);
}









