链表问题
#include<stdio.h>#include<stdlib.h>
#define len sizeof(struct student)
struct student
{
int num;
int socre;
struct student *next;
};
int n;
int main()
{
struct student *pt;
struct student *create(); //这里人如果写形参怎么写
void *print(struct student *);
pt=create();
print(pt);
return 0;
}
struct student *create()
{
n=0;
struct student *head;
struct student *p1,*p2;
p1=p2=(struct student*)malloc(len);
scanf("%d%d",&p1->num,&p1->socre);
head=NULL;
while(p1->num!=0)
{
n++;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student*)malloc(len);
scanf("%d%d",&p1->num,&p1->socre);
}
p2->next=NULL;
return head;
}
void print(struct student *p)
{
struct student *p3;
p3=p;
do
{
printf("%d%d\n",p3->num,p3->socre);
}while(p3!=NULL);
}
[此贴子已经被作者于2017-6-6 21:37编辑过]