输入若干个学生信息(包括学号、姓名和成绩),输入学号为0时输入结束,建立一个单向链表,再输入一个成绩值,将成绩大于等于该值的学生信息输出。
提示:
定义函数struct stud_node *Creat_Stu_Doc()完成创建链表
定义函数struct stud_node DeleteDoc(struct stud_node head,int min_score)将分数低于min_score的结点删除
定义函数void Ptrint_Stu_Doc(struct stud_node *head)打印链表
输入输出示例:括号内为说明,无需输入输出
输入样例:
1 zhang 78
2 wang 80
3 li 75
4 zhao 85
0
80
输出样例:
2 wang 80
4 zhao 85
#include <stdio.h>
#include <stdlib.h>
int score;
struct node
{
int su,data;
char s[100];
struct node *next;
};
struct node *Creat()
{
struct node *head,*tail,*p;
int x;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
while(scanf("%d",&x)!=EOF&&x)
{
p=(struct node *)malloc(sizeof(struct node));
p->su=x;
scanf("%s %d",p->s,&p->data);
p->next=tail->next;
tail->next=p;
tail=p;
}
return head;
}
struct node *Delete(struct node *head)
{
struct node *p,*q;
p=head;
q=head->next;
while(q)
{
if(q->data<score)
{
p->next=q->next;
free(q);
q=p->next;
}
else
{
p=q;
q=q->next;
}
}
return head;
}
void Printf(struct node *head)
{
struct node *tail;
tail=head->next;
while(tail)
{
printf("%d %s %d\n",tail->su,tail->s,tail->data);
tail=tail->next;
}
}
int main()
{
struct node *head;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
head=Creat();
scanf("%d",&score);
head=Delete(head);
Printf(head);
return 0;
}