#include
#include
struct student{
int num;
char name[10];
int gra;
struct student* next;
};
struct student *create();
int main(){
int n;
struct student *head,*p;
head=create();
scanf("%d",&n);
for(p=head->next;p!=NULL;p=p->next){
if(p->gra>=n) printf("%d %s %d\n",p->num,p->name,p->gra);
}
return 0;
}
struct student *create(){
struct student *head,*node,*end;
head=(struct student*)malloc(sizeof(struct student));
end=head;
// head->next=end;
while(1){
node=(struct student*)malloc(sizeof(struct student));
int num;
scanf("%d",&num);
if(num==0){
break;
}
node->num=num;
scanf("%s%d",node->name,&node->gra);
end->next=node;
end=node;
}
end->next=NULL;
return head;
}
因为如果删除了end=head之后end等于没有分配内存,是野指针。