@帮忙看看,刚学链表,实在不懂改哪里(另一种做法)
#include<stdio.h>#include<malloc.h>
struct student
{long num;
int scor;
struct student *next;
};
#define NULL 0
#define LEN sizeof(struct student)
struct student *fun()
{ int n=0,y;
long x;
struct student *p1,*p2,*head=NULL;
scanf("%ld,%d",&x,&y);
while(x!=0)
{ p1=(struct student *)malloc(LEN);
p1->num=x;
p1->scor=y;
n++;
if(n==1)
head=p2=p1;
else
{p2->next=p1;
p2=p1;
}
scanf("%ld,%d",&x,&y);
}
p2->next=NULL;
return(head);
}
void printf(struct student *head)
{
struct student *p1;
p1=head;
while(p1!=NULL)
{printf("%ld,%d",p1->num,p1->scor);
p1=p1->next;}
printf("\n");
}
void main()
{struct student *head;
head=fun();
printf(head);
}
[ 本帖最后由 浪漫横行 于 2013-5-20 12:44 编辑 ]