有2个链表,将它们合并,以下代码为什么不行?求解。
#include <stdio.h>#define NULL 0
struct xuesheng
{
int num;
float score[3];
struct xuesheng *next;
};
struct xuesheng * heada(void)
{
struct xuesheng l,m,n,*headx,*xp;
l.num=1;l.score[0]=90;l.score[1]=90;l.score[2]=90;
m.num=3;m.score[0]=80;m.score[1]=80;m.score[2]=80;
n.num=5;n.score[0]=70;n.score[1]=70;n.score[2]=70;
headx=&l;
l.next=&m;
m.next=&n;
n.next=NULL;
putchar('\n');
printf("输出函数1的链表\n");
for(xp=headx;xp!=0;xp=xp->next)
printf("%d,%f,%f,%f\n",xp->num,xp->score[0],xp->score[1],xp->score[2]);
putchar('\n');
putchar('\n');
return(headx);
}
struct xuesheng * headb(void)
{
struct xuesheng o,p,q,*heady,*xp;
o.num=2;o.score[0]=90;o.score[1]=90;o.score[2]=90;
p.num=4;p.score[0]=80;p.score[1]=80;p.score[2]=80;
q.num=6;q.score[0]=70;q.score[1]=70;q.score[2]=70;
heady=&o;
o.next=&p;
p.next=&q;
q.next=NULL;
printf("输出链表2\n");
for(xp=heady;xp!=NULL;xp=xp->next)
printf("%d,%f,%f,%f\n",xp->num,xp->score[0],xp->score[1],xp->score[2]);
putchar('\n');
putchar('\n');
return(heady);
}
main()
{ int i,j,n,v;
float f0;
struct xuesheng zp[6];
struct xuesheng *headnew,*p1,*p2;
p1=heada();
for(i=3;i<6;i++)
{
zp[i].num=p1->num;
for(v=0;v<3;v++)
zp[i].score[v]=p1->score[v];
p1=p1->next;
}
p1=headb();
for(i=3;i<6;i++)
{
zp[i].num=p1->num;
for(v=0;v<3;v++)
zp[i].score[v]=p1->score[v];
p1=p1->next;
}
for(j=0;j<5;j++)
for(i=0;i<5-j;i++)
if((zp[i]).num>(zp[i+1]).num)
{
n=zp[i].num;
zp[i].num=zp[i+1].num;
zp[i+1].num=n;
for(v=0;v<3;v++)
{ f0=zp[i].score[v];
zp[i].score[v]=zp[i+1].score[v];
zp[i+1].score[v]=f0;}
}
headnew=zp;
for(i=1;i<=4;i++)
zp[i].next=&zp[i+1];
zp[5].next=NULL;
for(p2=headnew;p2!=NULL;p2=p2->next)
printf("%d,%f,%f,%f\n",p2->num,p2->score[0],p2->score[1],p2->score[2]);
给的条件是2个有3个结点的链表。算法为:先将2个链表放置在以个结构体数组中,再对数组元素进行排序,编译时没有错误,运行时出现
以下提示:好像是内存不能被重置什么的,请有经验的同志给点提示。