除錯走了一步就出現unhandled exception了,程式題目是輸入一串數值,將其排i成二叉排序樹後輸出

  • 作者:由 匿名使用者 發表于 舞蹈
  • 2021-10-20

除錯走了一步就出現unhandled exception了,程式題目是輸入一串數值,將其排i成二叉排序樹後輸出網友09b5213 2011-05-25

構建二叉樹時,每一次都要為每一個結點分配空間哦

#include

#include

#define N 3

struct bitree

{

int key;

struct bitree *lchild;

struct bitree *rchild;

}*p;

bitree * bi_sort(struct bitree *p,int q)

{

if(p==NULL)

{

p=(struct bitree*)malloc(sizeof(struct bitree));

(*p)。lchild=NULL;

(*p)。rchild=NULL;

(*p)。key=q;

return p;

}

else

{

if(q<(*p)。key)

(*p)。lchild=bi_sort((*p)。lchild,q);

else

(*p)。rchild=bi_sort((*p)。rchild,q);

}

return p;

}

void in_order(struct bitree *p)

{

if(p!=NULL)

{

in_order((*p)。lchild);

printf(“%d”,(*p)。key);

in_order((*p)。rchild);

}

}

void main()

{

int i,a[N];

for(i=0;i

{printf(“%d”,i);

scanf(“%d”,&a[i]);

}

p=NULL;

for(i=0;i

p=bi_sort(p,a[i]);

in_order(p);

}

Top