已解决问题
这个生成链表的函数有什麼问题??
问题补充: p1重复开空间是什麼意思??还是这段代码有错??
struct student *creat()
/*返回一个指向链表头的指针*/
{
struct student *head;
struct student *p1, *p2;
n=0;
p1=(struct student*)malloc(LEN);
p2=(struct student*)malloc(LEN); /*开辟一个新单元*/
scanf("%d %f",&p1->num,&p1->score);
head=NULL;
while (p1->num!=0)
{
n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
scanf("%d %f",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}
提问者:tomore 提问时间:08-10-20 20:29
其他答案 (1)
