想了二天终于想把动态单向动态链表的门路摸到了,下面一自己写的一串代码,请高手指点下有哪些地方不足,需要改进的地方,谢谢!
#include<stdio.h>#include<stdlib.h>
struct student
{
int num;
float score;
struct student *pnext;
};
int main()
{
struct student *create(void);
struct student *temp;
temp=create();
while(temp!=NULL)
{
printf("%d %f\n",temp->num,temp->score);
temp=temp->pnext;
}
return 0;
}
struct student *create(void)
{
struct student *head,*p1,*p2;
p2=p1=(struct student*)malloc(sizeof(struct student));
scanf("%d %f",&p1->num,&p1->score);
if(p1->num==0)
{
head=NULL;
return (head);
}
head=p1;
while(p1->num!=0)
{
p1=(struct student*)malloc(sizeof(struct student));
scanf("%d %f",&p1->num,&p1->score);
p2->pnext=p1;
if(p1->num==0)
{
p2->pnext=NULL;
free(p1);
return head;
}
p2=p1;
}
return 0;
}