这个建立链表的程序有没有问题?
下面是一个建立链表的程序,老师写的,我觉得有点小问题,大家帮我看看。# include "stdio.h"
struct student{
int num;
float score;
struct student * next;
};
struct student *creat();
main()
{
struct student *head;
head=creat();
}
struct student *creat()
{
struct student *head,*tail,*p;
float score;
int num,size=sizeof(struct student);
head=tail=NULL;
scanf("%d%f",&num,&score);
while(num){
p=(struct student *)malloc (size);
p->num=num;p->score=score;
p->next=NULL;
if(head==NULL) head=p;
else tail->next=p;
tail=p;
scanf("%d%f",&num,&score);
}
return head;
}
这段程序建立了单向链表,但好像链表的尾指针不是NULL,我觉得应该在return head的前面加上一句:tail->next=NULL
高手帮我看看是不是这样,谢谢!
[[it] 本帖最后由 ronaldfree 于 2008-8-14 15:34 编辑 [/it]]