有头结点
void input()
{
struct stud_node *p=(struct stud_node*)malloc(sizeof (struct stud_node));
head=p;
int in;
scanf("%d",&in);
while(in)
{
p->next=(struct stud_node*)malloc(sizeof (struct stud_node));
p=p->next;
p->num=in;
scanf("%s",p->name);
scanf("%d",&p->score);
scanf("%d",&in);
}
p->next=NULL;
head=head->next;
}
或者无头结点
void input()
{
struct stud_node *p=NULL ,*temp =NULL;
int x;
scanf("%d",&x);
while(x ){
temp = (struct stud_node*)malloc(sizeof(struct stud_node));
temp->num = x;
scanf("%s",temp->name);
scanf("%d",&temp->score);
if(p==NULL)
head = p = temp;
else{
p->next = temp;
p = temp;
}
scanf("%d",&x);
}
}