📄 text1.c
字号:
mythis->all_score=mythis->chinese_score+mythis->math_score+mythis->english_score;
mythis->average_score=(mythis->chinese_score+mythis->math_score+mythis->english_score)/3;
system("cls");
printf("Success!\n");
break;
}
}
}
void set()
{
struct student *p1,*p2;
p1=myhead;
while(myhead->next!=NULL)
{
p2=p1;
p1=myhead->next;
myhead->next=p1->next;
p1->next=p2;
}
myhead=p1;
system("cls");
printf("Success!!\n");
}
struct student *sort1() /*语文成绩升序排列*/
{
struct student *q,*tail,*p=(struct student*)malloc(sizeof(struct student));
p->next=myhead;
myhead=p;
tail=NULL;
while(tail!=myhead->next)
{
p=myhead;
q=p->next;
while(q->next!=tail)
{
if(p->next->chinese_score > q->next->chinese_score)
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
tail=q;
}
p=myhead->next;
free(myhead);
myhead=p;
return p;
}
struct student *sort2() /*语文成绩降序排列*/
{
struct student *q,*tail,*p=(struct student*)malloc(sizeof(struct student));
p->next=myhead;
myhead=p;
tail=NULL;
while(tail!=myhead->next)
{
p=myhead;
q=p->next;
while(q->next!=tail)
{
if(p->next->chinese_score < q->next->chinese_score)
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
tail=q;
}
p=myhead->next;
free(myhead);
myhead=p;
return p;
}
struct student *sort3() /*数学成绩升序排列*/
{
struct student *q,*tail,*p=(struct student*)malloc(sizeof(struct student));
p->next=myhead;
myhead=p;
tail=NULL;
while(tail!=myhead->next)
{
p=myhead;
q=p->next;
while(q->next!=tail)
{
if(p->next->math_score > q->next->math_score)
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
tail=q;
}
p=myhead->next;
free(myhead);
myhead=p;
return p;
}
struct student *sort4() /*数学成绩降序排列*/
{
struct student *q,*tail,*p=(struct student*)malloc(sizeof(struct student));
p->next=myhead;
myhead=p;
tail=NULL;
while(tail!=myhead->next)
{
p=myhead;
q=p->next;
while(q->next!=tail)
{
if(p->next->math_score < q->next->math_score)
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
tail=q;
}
p=myhead->next;
free(myhead);
myhead=p;
return p;
}
struct student *sort5() /*英语成绩升序排列*/
{
struct student *q,*tail,*p=(struct student*)malloc(sizeof(struct student));
p->next=myhead;
myhead=p;
tail=NULL;
while(tail!=myhead->next)
{
p=myhead;
q=p->next;
while(q->next!=tail)
{
if(p->next->english_score > q->next->english_score)
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
tail=q;
}
p=myhead->next;
free(myhead);
myhead=p;
return p;
}
struct student *sort6() /*英语成绩升序排列*/
{
struct student *q,*tail,*p=(struct student*)malloc(sizeof(struct student));
p->next=myhead;
myhead=p;
tail=NULL;
while(tail!=myhead->next)
{
p=myhead;
q=p->next;
while(q->next!=tail)
{
if(p->next->english_score < q->next->english_score)
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
tail=q;
}
p=myhead->next;
free(myhead);
myhead=p;
return p;
}
struct student *sort7() /*平均成绩升序排列*/
{
struct student *q,*tail,*p=(struct student*)malloc(sizeof(struct student));
p->next=myhead;
myhead=p;
tail=NULL;
while(tail!=myhead->next)
{
p=myhead;
q=p->next;
while(q->next!=tail)
{
if(p->next->average_score > q->next->average_score)
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
tail=q;
}
p=myhead->next;
free(myhead);
myhead=p;
return p;
}
struct student *sort8() /*平均成绩降序排列*/
{
struct student *q,*tail,*p=(struct student*)malloc(sizeof(struct student));
p->next=myhead;
myhead=p;
tail=NULL;
while(tail!=myhead->next)
{
p=myhead;
q=p->next;
while(q->next!=tail)
{
if(p->next->average_score < q->next->average_score)
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
tail=q;
}
p=myhead->next;
free(myhead);
myhead=p;
return p;
}
struct student *sort9() /*总成绩升序排列*/
{
struct student *q,*tail,*p=(struct student*)malloc(sizeof(struct student));
p->next=myhead;
myhead=p;
tail=NULL;
while(tail!=myhead->next)
{
p=myhead;
q=p->next;
while(q->next!=tail)
{
if(p->next->all_score > q->next->all_score)
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
tail=q;
}
p=myhead->next;
free(myhead);
myhead=p;
return p;
}
struct student *sort10() /*总成绩降序排列*/
{
struct student *q,*tail,*p=(struct student*)malloc(sizeof(struct student));
p->next=myhead;
myhead=p;
tail=NULL;
while(tail!=myhead->next)
{
p=myhead;
q=p->next;
while(q->next!=tail)
{
if(p->next->all_score < q->next->all_score)
{
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
}
p=p->next;
q=p->next;
}
tail=q;
}
p=myhead->next;
free(myhead);
myhead=p;
return p;
}
main()
{
int m,a;
while(1)
{
printf("|---------------欢迎进入学生信息系统-----------------|\n");
printf("|------------------------+---------------------------|\n");
printf("|------------------请选择以下功能--------------------|\n");
printf("|----------------------------------------------------|\n");
printf("| 1.建立单链表 | 2.输出单链表 |\n");
printf("| 3.查找单链表 | 4.插入单链表 |\n");
printf("| 5.删除单链表 | 6.更新单链表 |\n");
printf("| 7.设置单链表 | 8.排序单链表 |\n");
printf("| 0.退出系统 |\n");
printf("|------------------------+---------------------------|\n");
printf("choose:\n");
scanf("%d",&m);
switch(m)
{
case 1:creat(); break;
case 2:print();break;
case 3:search();break;
case 4:add();break;
case 5:delt();break;
case 6:renew();break;
case 7:set();break;
case 8:
{
system("cls");
printf("排序方式!!!\n");
printf("+-------------------------------------------+\n");
printf("| 1、语文成绩升序排列 | 2、语文成绩降序排列 |\n");
printf("| 3、数学成绩升序排列 | 4、数学成绩降序排列 |\n");
printf("| 5、英语成绩升序排列 | 6、英语成绩降序排列 |\n");
printf("| 7、平均成绩升序排列 | 8、平均成绩降序排列 |\n");
printf("| 9、总成绩升序排列 | 10、总成绩降序排列 |\n");
printf("+-------------------------------------------+\n");
printf("choose:");
scanf("%d",&a);
if(a!=1&&a!=2&&a!=3&&a!=4&&a!=5&&a!=6&&a!=7&&a!=8&&a!=9&&a!=10)
{
printf("Erorr!please choose agian\n");
}
else
switch(a)
{ case 0: exit(0);break;
case 1: sort1();print();break;
case 2: sort2();print();break;
case 3:sort3();print();break;
case 4:sort4();print();break;
case 5:sort5();print();break;
case 6: sort6();print();break;
case 7:sort7();print();break;
case 8:sort8();print();break;
case 9:sort9();print();break;
case 10:sort10();print();break;
default:
printf("choice errro!\npress any key to continue...\n");
break;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -