#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct stu * list;
struct stu{
int num,score;
char name[20];
struct stu * next;
};
list create666(){
list head,p,tail;
head=NULL;
int num,score;
char name[20];
scanf("%d",&num);
scanf("%s",name);
scanf("%d",&score);
while(1){
p=(list)malloc(sizeof(struct stu));
scanf("%d",&num);
if(num==0)
break; //这一步一定要用while(1)而不用书上的最后加scanf 因为最后会在缓冲区留下无用的数
p->num=num; //影响后续输入min
scanf("%s",p->name);
scanf("%d",&p->score);
p->next=NULL;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
}
return head;
}
list delete666(list head,int min){
list p1,p2;
while(head!=NULL&&head->score<min){
p2=head;
head=head->next;
free(p2);
}
if(head==NULL)
return NULL;
p1=head;
p2=head->next;
while(p2!=NULL){
if(p2->score<min){
p1->next=p2->next;
free(p2);
}
else
p1=p2;
p2=p1->next;
}
return head;
}
void print666(list head){
list p;
for(p=head;p!=NULL;p=p->next)
printf("%d %s %d\n",p->num,p->name,p->score);
}
int main(){
list head;
head=create666();
int min;
scanf("%d",&min);
head=delete666(head,min);
print666(head);
return 0;
}
7-2 成绩大于等于某值的学生信息输出
猜你喜欢
转载自blog.csdn.net/KEVINzzh/article/details/105112813
今日推荐
周排行