NEFU锐格实验十[链表3-基本应用]
知识点
题目 | 知识点 |
---|---|
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;
}