怎样创建一个链表
怎样创建一个链表struct student *create()
{
struct student *head,*p1,*p2;
int i=0,n;
head=NULL;
printf("plaese input n:");
scanf("%d",&n);
p1=((struct student *)malloc(sizeof(struct student)));
p2=((struct student *)malloc(sizeof(struct student)));
scanf("%d",&p1->num);
//scanf("%s",p1->name);
//fflush(stdin);
// printf("plase input sex,f-女,m-男:");
// scanf("%c",&p1->sex);
//fflush(stdin);
//scanf("%d",&p1->old);
for(i=0;i<n;i++)
{
if(i==0)
head=p1;
else{
p1->next=NULL;
p2->next=p1;
p2=p1;
}
p1=(struct student *)malloc(sizeof(struct student));
scanf("%d",&p1->num);
}
free(p1);
return(head);
}