共回答了20个问题采纳率:100%
#include
#include
#define NULL0
#define LEN sizeof(struct student)
struct student
{
long num;
char name[20];
float score1;
float score2;
float score3;
float score4;
float score5;
float c;
float z;
struct student *next;
};
int n;
struct student *creat(void)
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld,%f,%f,%f,%f,%f,%s",&p1->num,&p1->score1,&p1->score2,&p1->score3,&p1->score4,&p1->score5,p1->name);
head=NULL;
while(p1->num!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
scanf("%ld,%f,%f,%f,%f,%f,%s",&p1->num,&p1->score1,&p1->score2,&p1->score3,&p1->score4,&p1->score5,p1->name);
}
p2->next=NULL;
return(head);
}
void print(struct student *head)
{
struct student *p;
printf("nNow,these %d records are:n",n);
p=head;
if(head!=NULL)
do
{
p->z=(p->score1)+(p->score2)+(p->score3)+(p->score4)+(p->score5);
p->c=(p->z)/5;
printf("%ld %5.1f%5.1f%5.1f%5.1f%5.1f %s ",p->num,p->score1,p->score2,p->score3,p->score4,p->score5,p->name);
printf("总分=%f 平均分=%fn",p->z,p->c);
p=p->next;
}
while(p!=NULL);
}
struct student *del(struct student *head,long num)
{
struct student *p1,*p2;
if(head==NULL)
{printf("nlist nulln");
return head;}
p1=head;
while(num!=p1->num && p1->next!=NULL)
{p2=p1;
p1=p1->next;
}
if(num==p1->num)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
printf("delete:%ldn",num);
n=n-1;
free(p1);
}
else printf("%ld not been found!n",num);
return(head);
}
struct student *insert(struct student *head,struct student *stud)
{
struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{
while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->numnum)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{p1->next=p0;p0->next=NULL;}
}
n=n+1;
return(head);
}
struct student * ordination(struct student * head)
{
struct student * first;
struct student * tail;
struct student * p_min;
struct student * min;
struct student * p;
first=NULL;
while(head!=NULL)
{
for(p=head,min=head;p->next!=NULL;p=p->next)
{
if(p->next->numnum)
{
p_min=p;
min=p->next;
}
}
if(first==NULL)
{
first=min;
tail=min;
}
else
{
tail->next=min;
tail=min;
}
if(min==head)
{
head=head->next;}
else{p_min->next=min->next;}
}
if(first!=NULL)
{
tail->next=NULL;
}
head=first;
return(head);
}
struct student * ordinationc(struct student * head)
{
struct student * first;
struct student * tail;
struct student * p_min;
struct student * min;
struct student * p;
first=NULL;
while(head!=NULL)
{
for(p=head,min=head;p->next!=NULL;p=p->next)
{
if(p->next->z>min->z)
{
p_min=p;
min=p->next;
}
}
if(first==NULL)
{
first=min;
tail=min;
}
else
{
tail->next=min;
tail=min;
}
if(min==head)
{
head=head->next;}
else{p_min->next=min->next;}
}
if(first!=NULL)
{
tail->next=NULL;
}
head=first;
return(head);
}
struct student *cha(struct student *head,long cha)
{
struct student *p1,*p2;
if(head==NULL)
{printf("nlist nulln");
return head;}
p1=head;
while(cha!=p1->num && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(cha==p1->num)
{
printf("%ld,%5.1f%5.1f%5.1f%5.1f%5.1f,%sn",p1->num,p1->score1,p1->score2,p1->score3,p1->score4,p1->score5,p1->name);
}
else printf("%ld not been found!n",cha);
return(head);
}
struct student *chap(struct student *head)
{
struct student *p1,*p2;
int x;
x=1;
if(head==NULL)
{printf("nlist nulln");
return head;}
p1=head;
while( p1->next!=NULL)
{
if(p1->c>85)
{
printf("%ld,%5.1f%5.1f%5.1f%5.1f%5.1f,%sn",p1->num,p1->score1,p1->score2,p1->score3,p1->score4,p1->score5,p1->name);
x=0;
}
p1=p1->next;
}
if(x) printf("没有平均分在85分以上的学生n");
return(head);
}
struct student *chapb(struct student *head)
{
struct student *p1,*p2;
int x;
x=1;
if(head==NULL)
{printf("nlist nulln");
return head;}
p1=head;
while( p1->next!=NULL)
{
if(p1->cnum,p1->score1,p1->score2,p1->score3,p1->score4,p1->score5,p1->name);
x=0;
}
p1=p1->next;
}
if(x) printf("没有不及格的学生n");
return(head);
}
void main()
{
struct student * head, * stu;
long del_num;
long cha_num;
printf("input record:(学号、5科成绩、姓名)n");
head=creat();
print(head);
printf("ninput the deleted number:");
scanf("%ld",&del_num);
while(del_num!=0)
{
head=del(head,del_num);
print(head);
printf("input the deleted number:");
scanf("%ld",&del_num);
}
printf("ninput the inserted record:");
stu=(struct student * )malloc(LEN);
scanf("%ld,%f,%f,%f,%f,%f,%s",&stu->num,&stu->score1,&stu->score2,&stu->score3,&stu->score4,&stu->score5,stu->name);
while(stu->num!=0)
{
head=insert(head,stu);
print(head);
printf("input the inserted record:");
stu=(struct student * )malloc(LEN);
scanf("%ld,%f,%f,%f,%f,%f,%s",&stu->num,&stu->score1,&stu->score2,&stu->score3,&stu->score4,&stu->score5,stu->name);
}
printf("ninput the 查找 number:");
scanf("%ld",&cha_num);
while(cha_num!=0)
{
head=cha(head,cha_num);
printf("input the 查找 number:");
scanf("%ld",&cha_num);
}
printf("下面是85分以上的:nn");
head=chap(head);
printf("n");
printf("下面是不及格的:nn");
head=chapb(head);
printf("n");
printf("下面是学号排序");
head=ordination(head);
print(head);
printf("nn");
printf("总分排序");
head=ordinationc(head);
print(head);
}
这是我上学期的作业,跟你的差不多
1年前
9