NEFU锐格实验十[链表3-基本运用]

NEFU锐格实验十[链表3-基本应用]

推荐:NEFU大一下C语言锐格实验与作业参考程序目录

知识点

题目知识点
5830查找前驱
5831查询变形
5832删除
5833链表插入排序
5834链表插入

题目

加了点数据处理罢了

5830

#include<stdio.h>
#include<stdlib.h>

typedef struct Student
{
    int id;
    char name[20];
    double a,b,c,ave,sum;
    struct Student * next;
}Lnode;

void CreatList_Tail(Lnode * H,int n)
{
    Lnode * p, * r;
    r=H;
    for(int i=0;i<n;i++)
    {
        p=(Lnode *)malloc(sizeof (Lnode));
        if(p==NULL)printf("Fail\n");
        scanf("%d  %s  %lf  %lf  %lf\n",&p->id,p->name,&p->a,&p->b,&p->c);
        p->sum=p->a+p->b+p->c;
        p->ave=p->sum/3.0;
        r->next=p;r=p;
    }   
    r->next=NULL;

}

void PrintList(Lnode * H)
{
    Lnode * p;
    p=H->next;
    while(p!=NULL)
    {
        printf("%d  %s  %.2lf  %.2lf  %.2lf  %.2lf  %.2lf  \n",p->id,p->name,p->a,p->b,p->c,p->ave,p->sum);
        p=p->next;
    }
}
int main()
{
    int n;
    Lnode * H;
    while(~scanf("%d",&n))
    {
        H=(Lnode *)malloc(sizeof (Lnode));H->next=NULL;
        CreatList_Tail(H,n);
        PrintList(H);
    }
    return 0;
}

5831

#include<stdio.h>
#include<stdlib.h>

typedef struct Student
{
    int id;
    char name[20];
    double a,b,c,ave,sum;
    struct Student * next;
}Lnode;

void CreatList_Tail(Lnode * H,int n)
{
    Lnode * p, * r;
    r=H;
    for(int i=0;i<n;i++)
    {
        p=(Lnode *)malloc(sizeof (Lnode));
        if(p==NULL)printf("Fail\n");
        scanf("%d  %s  %lf  %lf  %lf\n",&p->id,p->name,&p->a,&p->b,&p->c);
        p->sum=p->a+p->b+p->c;
        p->ave=p->sum/3.0;
        r->next=p;r=p;
    }   
    r->next=NULL;

}
Lnode * SearchList(Lnode * H,int no,int * w)
{
    Lnode * p;
    int cnt=1;
    p=H->next;
    while(p!=NULL&&p->id!=no)
    {
        ++cnt;
        p=p->next;
    }
    *w=cnt;
    return p;
}
void PrintList(Lnode * H)
{
    Lnode * p;
    p=H->next;
    while(p!=NULL)
    {
        printf("%d  %s  %.2lf  %.2lf  %.2lf  %.2lf  %.2lf  \n",p->id,p->name,p->a,p->b,p->c,p->ave,p->sum);
        p=p->next;
    }
    puts("");
}
int main()
{
    int n,x,w;
    Lnode * H,* p;
    while(~scanf("%d",&n))
    {
        H=(Lnode *)malloc(sizeof (Lnode));H->next=NULL;
        CreatList_Tail(H,n);
        scanf("%d",&x);
        p=SearchList(H,x,&w);
        if(p!=NULL)printf("%d  %d  %s  %.2lf  %.2lf  %.2lf  %.2lf  %.2lf  \n",w,p->id,p->name,p->a,p->b,p->c,p->ave,p->sum);
        else printf("0\n");
    }
    return 0;
}

5832

#include<stdio.h>
#include<stdlib.h>

typedef struct Student
{
    int id;
    char name[20];
    double a,b,c,ave,sum;
    struct Student * next;
}Lnode;

void CreatList_Tail(Lnode * H,int n)
{
    Lnode * p, * r;
    r=H;
    for(int i=0;i<n;i++)
    {
        p=(Lnode *)malloc(sizeof (Lnode));
        if(p==NULL)printf("Fail\n");
        scanf("%d  %s  %lf  %lf  %lf\n",&p->id,p->name,&p->a,&p->b,&p->c);
        p->sum=p->a+p->b+p->c;
        p->ave=p->sum/3.0;
        r->next=p;r=p;
    }   
    r->next=NULL;

}
Lnode * SearchList(Lnode * H,int no,int * w)
{
    Lnode * p;
    int cnt=0;
    p=H->next;
    while(p!=NULL&&p->id!=no)
    {
        ++cnt;
        p=p->next;
    }
    *w=cnt;
    return p;
}
void PrintList(Lnode * H)
{
    Lnode * p;
    p=H->next;
    while(p!=NULL)
    {
        printf("%d  %s  %.2lf  %.2lf  %.2lf  %.2lf  %.2lf  \n",p->id,p->name,p->a,p->b,p->c,p->ave,p->sum);
        p=p->next;
    }
 //   puts("");
}
void InsertList(Lnode * H,Lnode * x)
{
    Lnode * p,* pre;
    pre=H;
    p=H->next;
    while(p!=NULL&&p->id<x->id)
    {
        pre=p;
        p=p->next;
    }
    x->next=p;
    pre->next=x;

}
int main()
{
    int n,x,w;
    Lnode * H,* p;
    while(~scanf("%d",&n))
    {
        H=(Lnode *)malloc(sizeof (Lnode));H->next=NULL;
        CreatList_Tail(H,n);
        p=(Lnode *)malloc(sizeof (Lnode));
        scanf("%d  %s  %lf  %lf  %lf\n",&p->id,p->name,&p->a,&p->b,&p->c);
        p->sum=p->a+p->b+p->c;
        p->ave=p->sum/3.0;
        InsertList(H,p);
        PrintList(H);
    }
    return 0;
}

5833

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

typedef struct Student
{
    int id;
    char name[20];
    double a,b,c,ave,sum;
    struct Student * next;
}Lnode;

void CreatList_Tail(Lnode * H,int n)
{
    Lnode * p, * r;
    r=H;
    for(int i=0;i<n;i++)
    {
        p=(Lnode *)malloc(sizeof (Lnode));
        if(p==NULL)printf("Fail\n");
        scanf("%d  %s  %lf  %lf  %lf\n",&p->id,p->name,&p->a,&p->b,&p->c);
        p->sum=p->a+p->b+p->c;
        p->ave=p->sum/3.0;
        r->next=p;r=p;
    }   
    r->next=NULL;

}
Lnode * SearchList(Lnode * H,int no,int * w)
{
    Lnode * p;
    int cnt=0;
    p=H->next;
    while(p!=NULL&&p->id!=no)
    {
        ++cnt;
        p=p->next;
    }
    *w=cnt;
    return p;
}
void PrintList(Lnode * H)
{
    Lnode * p;
    p=H->next;
    while(p!=NULL)
    {
        printf("%d  %s  %.2lf  %.2lf  %.2lf  %.2lf  %.2lf  \n",p->id,p->name,p->a,p->b,p->c,p->ave,p->sum);
        p=p->next;
    }
 //   puts("");
}
void InsertList(Lnode * H,Lnode * x)
{
    Lnode * p,* pre;
    pre=H;
    p=H->next;
    while(p!=NULL&&p->id<x->id)
    {
        pre=p;
        p=p->next;
    }
    x->next=p;
    pre->next=x;

}

bool RemoveList(Lnode * H,int no)
{
    Lnode * p,* pre,* tmp;
    pre=H;p=H->next;
    while(p!=NULL&&p->id!=no)
    {
        pre=p;
        p=p->next;
    }
    if(p==NULL)return 0;
    else
    {
        tmp=p;
        pre->next=p->next;
        free(tmp);
        return 1;
    }
}
int main()
{
    int n,x,w;
    Lnode * H,* p;
    while(~scanf("%d",&n))
    {
        H=(Lnode *)malloc(sizeof (Lnode));H->next=NULL;
        CreatList_Tail(H,n);
        scanf("%d",&x);
        bool f=RemoveList(H,x);
        if(f)PrintList(H);
        else printf("Error\n");
    }
    return 0;
}

5834

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

typedef struct Student
{
    int id;
    char name[20];
    double a,b,c,ave,sum;
    struct Student * next;
}Lnode;

void CreatList_Tail(Lnode * H,int n)
{
    Lnode * p, * r;
    r=H;
    for(int i=0;i<n;i++)
    {
        p=(Lnode *)malloc(sizeof (Lnode));
        if(p==NULL)printf("Fail\n");
        scanf("%d  %s  %lf  %lf  %lf\n",&p->id,p->name,&p->a,&p->b,&p->c);
        p->sum=p->a+p->b+p->c;
        p->ave=p->sum/3.0;
        r->next=p;r=p;
    }   
    r->next=NULL;

}
Lnode * SearchList(Lnode * H,int no,int * w)
{
    Lnode * p;
    int cnt=0;
    p=H->next;
    while(p!=NULL&&p->id!=no)
    {
        ++cnt;
        p=p->next;
    }
    *w=cnt;
    return p;
}
void PrintList(Lnode * H)
{
    Lnode * p;
    p=H->next;
    while(p!=NULL)
    {
        printf("%d  %s  %.2lf  %.2lf  %.2lf  %.2lf  %.2lf  \n",p->id,p->name,p->a,p->b,p->c,p->ave,p->sum);
        p=p->next;
    }
 //   puts("");
}
void InsertList(Lnode * H,Lnode * x)
{
    Lnode * p,* pre;
    pre=H;
    p=H->next;
    while(p!=NULL&&p->sum>x->sum)
    {
        pre=p;
        p=p->next;
    }
    x->next=p;
    pre->next=x;

}

bool RemoveList(Lnode * H,int no)
{
    Lnode * p,* pre,* tmp;
    pre=H;p=H->next;
    while(p!=NULL&&p->id!=no)
    {
        pre=p;
        p=p->next;
    }
    if(p==NULL)return 0;
    else
    {
        tmp=p;
        pre->next=p->next;
        free(tmp);
    }
    
}
int main()
{
    int n,x,w;
    Lnode * H,* p;
    while(~scanf("%d",&n))
    {
        H=(Lnode *)malloc(sizeof (Lnode));H->next=NULL;
        for(int i=0;i<n;i++)
        {
            p=(Lnode *)malloc(sizeof (Lnode));
            scanf("%d  %s  %lf  %lf  %lf\n",&p->id,p->name,&p->a,&p->b,&p->c);
            p->sum=p->a+p->b+p->c;
            p->ave=p->sum/3.0;
            InsertList(H,p);
        }
        PrintList(H);
    }
    return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值