7-5 成绩大于等于某值的学生信息输出 (10分)

输入若干个学生信息(包括学号、姓名和成绩),输入学号为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;
}
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值