# C语言使用单链表实现学生信息管理系统

1.运行界面

2.录入学生信息

3.按照总分进行排序

```#define ERROR 0
#define OK 1
#define OVERFLOW -1;
typedef int ElemType;
typedef int Status;
#include
#include
#include
#include
#include
typedef struct{
char name[20];
char snumber[20];
char sex[10];
int math;
int chinese;
int english;
}student;
typedef struct LNode{
student data;
struct LNode *next;
//单链表初始化
L = new LNode;
L->next = NULL;
return OK;
}
//创建单链表
L = new LNode;
L->next = NULL;
r = L;
int i;
for(i = 0;idata.name,&p->data.snumber,&p->data.sex,&p->data.chinese,&p->data.math,&p->data.english);
//scanf("%d%d%d",&p->data.chinese,&p->data.math,&p->data.english);
p->next=NULL;
r->next=p;
r = p;
}
}

//总分统计
int sum;
sum = (L->data.chinese)+(L->data.english)+(L->data.math);
return sum;
}
//统计所有学生信息
p = L->next;
printf("姓名\t学号\t性别\t语文\t数学\t英语\t总分\n");
while(p){
printf("%s\t%s\t%s\t",p->data.name,p->data.snumber,p->data.sex);
p = p->next;
printf("\n");
}
}
//按照总分排序

tail = NULL;

while((L->next->next) != tail)
{
p = L;
q = L->next;
while(q->next != tail)
{
{
p->next = q->next;
q->next = q->next->next;
p->next->next = q;
q = p->next;
}
q = q->next;
p = p->next;
}
tail = q;
}
printf("排序完毕！\n");

}
//根据语文进行排序

tail = NULL;

while((L->next->next) != tail)
{
p = L;
q = L->next;
while(q->next != tail)
{
if((q->data.chinese) < (q->next->data.chinese))
{
p->next = q->next;
q->next = q->next->next;
p->next->next = q;
q = p->next;
}
q = q->next;
p = p->next;
}
tail = q;
}
printf("排序完毕！\n");

}
//根据英语进行排序

tail = NULL;

while((L->next->next) != tail)
{
p = L;
q = L->next;
while(q->next != tail)
{
if((q->data.english) < (q->next->data.english))
{
p->next = q->next;
q->next = q->next->next;
p->next->next = q;
q = p->next;
}
q = q->next;
p = p->next;
}
tail = q;
}
printf("排序完毕！\n");

}
//根据数学进行排序

tail = NULL;

while((L->next->next) != tail)
{
p = L;
q = L->next;
while(q->next != tail)
{
if((q->data.math) < (q->next->data.math))
{
p->next = q->next;
q->next = q->next->next;
p->next->next = q;
q = p->next;
}
q = q->next;
p = p->next;
}
tail = q;
}
printf("排序完毕！\n");

}
//删除学生信息
int j;
p = L;j = 0;
while((p->next)&&(jnext;
++j;
}
if(!(p->next)||(j>i-1)) return ERROR;
q = p->next;
p->next = q->next;
delete q;
return OK;
}
int i;
printf("请输入需要删除的学生序号\n");
scanf("%d",&i);
ListDelete(L,i);
printf("删除完毕！\n");

}
//插入学生信息
Status ListInsert(LinkList &L,int i,char name[],char snumber[],char sex[],int chinese,int math,int english){
int j = 0;
while(p && (jnext;
++j;
}
if(!p||j>i-1) return ERROR;
s = new LNode;
strcpy(s->data.name,name);
strcpy(s->data.snumber,snumber);
strcpy(s->data.sex,sex);
s->data.chinese = chinese;
s->data.math = math;
s->data.english = english;
s->next = p->next;
p->next = s;
return OK;
}
int n;
char name[20],snumber[20],sex[10];
int chinese,math,english;
printf("请输入插入的位置N：");
scanf("%d",&n);
printf("请依次输入学生的姓名、学号、性别、语文成绩、数学成绩、英语成绩、总分\n");
scanf("%s%s%s%d%d%d",&name,&snumber,&sex,&chinese,&math,&english);
ListInsert(L,n,name,snumber,sex,chinese,math,english);

}
printf("\t\t\t  ======================================================\n\n");
printf("\t\t\t ‖                学生信息管理系统                    ‖ \n\n");
printf("\t\t\t  ======================================================\n\n");
printf("\t\t\t  ===================系统功能菜单=======================\n");
printf("\t\t\t ‖  ------------------------------------------------  ‖\n");
printf("\t\t\t ‖  ------------------------------------------------  ‖ \n");
printf("\t\t\t  ======================================================  \n");
printf("\t\t\t ‖    0.录入学生信息      ‖ ‖  1.统计学生信息       ‖     \n");
printf("\t\t\t  ======================================================\n");
printf("\t\t\t ‖    2.按照总分排序      ‖ ‖  3.按照语文成绩排序   ‖     \n");
printf("\t\t\t  ====================================================== \n");
printf("\t\t\t ‖    4.按照数学成绩排序  ‖ ‖  5.按英语成绩排序     ‖    \n");
printf("\t\t\t  ======================================================\n");
printf("\t\t\t ‖    6.删除学生信息      ‖ ‖  7.插入学生信息       ‖    \n");
printf("\t\t\t  ====================================================== \n");
printf("\t\t\t ‖    8.退出系统          ‖         \n");
printf("\t\t\t  ==========================     \n");
printf("\t\t\t     -----------------------------------------------  \n");
printf("\n\n\n");
}
int n;
printf("请输入学生数目N：");
scanf("%d",&n);
printf("请依次输入学生的姓名、学号、性别、语文成绩、数学成绩、英语成绩、总分\n");
CreateList(L,n);
printf("学生信息已录入完毕！\n");
}
void main(int args,char argv[]){
InitList(p);
int i;
do{
scanf("%d",&i);
getchar();
switch(i){
case 0:luRu(p);break;
case 1:BianLi(p);break;
case 2:OrderSum(p);BianLi(p);break;
case 3:OrderChinese(p);BianLi(p);break;
case 4:OrderMath(p);BianLi(p);break;
case 5:OrderEnglish(p);BianLi(p);break;
case 6: DeleteStudent(p);break;
case 7:InsertStudent(p);break;
case 8:exit(0);
}
}while(i != -1);
}```