#include<stdio.h>
#include<stdlib.h>
#include<sting.h>
#define LEN sizeof(struct link)
#define NULL 0
typedef struct link {
int number;
char name[10];
double math;
double english;
double china;
float average;
struct link *next;
} ;
typedef link *list
link *head(int N)
{
list head,one,two;
int i;
one=(list)malloc(LEN);
if(one!=NULL)
head=two=one;
one->next=NULL;
two->next=NULL;
printf("请输入学生数据:\n")
for(i=0;i<N;i++)
{
printf("学生学号:\n");
scanf("%d",&one->number);
printf("学生姓名:\n");
scanf("%s",&one->name);
printf("数学:\n");
scanf("%d",&one->math);
printf("英语:\n");
scanf("%d",&one->english);
printf("语文:\n");
scanf("%d",&one->china);
one->average=((one->math)+(one->english)+(one->china))/3
one=(LIST *)malloc(LEN);
two->next=one;
two=one;
}
two->next=NULL;
two=one=head;
return head;
}
viod prinf_student(list head)//链表的打印
{
list ps;
if(head==NULL)
{
printf("空链表");
getch();
exit(1);
}
ps=head;
while(ps=NULL)
{
printf("学号\t\t姓名\t\t数学\t\t英语\t\t语文\t\t平均成绩\n");
printf("%d\t\t%s\t\t%d\t\t%d\t\t%d\t\t%f\n",ps->number,ps->name,ps->math,ps->english,ps->china,ps->average);
ps=ps->next;
}
free(ps);
}
insert_student(list pss,list head)//插入学生成绩(在主函数中建立一个学生的信息)
{
list one,two,three;
one=pss;
two=head;
if(head=NULL)
{
head=one;
pss->next=NULL;
}
else
{
while((one->average<two->average)&&(two->next!=NULL))//查询
{
three=two;
two=two->next;
}
if(one->average=>two->average)
{
three->next=one;
one->next=two;
}
else
{
two->next=one;
one->next=NULL;
}
}
printf("插入成功");
one=two=three=head;//这一步不知是否多次一举
return head;
}
link *delete_student(int num,list head)//按学号删除学生记录(输入学生学号)
{
list p0,p1,p2;
p0=head;
while((num!=p0->number)&&(p0->next!=NULL))
{
p1=p0;
p0=p0->next;
}
if(num==p0->number)
{
p1->next=p0-next;
printf("学号%d资料删除成功",p0->num);
}
else{
printf("没有该学号");
}
return head;
}
link *order_list(list head)//排序
{
list temp,ps;
link tempdate;
tempdate->next=NULL;
ps=head;
if("ps==NULL")
{
printf("链表为空");
getch();
exit(1);
}
for(ps=head;ps=NULL;ps=ps->next)
{
for(temp=ps->next;temp=NULL;temp=temp->next)
{
if(ps->average<=ps->average)
{
tempdate->number=temp->nunber;
tempdate->name=temp->name;
tempdate->math=temp->math;
tempdate->english=tem->english;
tempdate->china=temp->china;
tempdate->average=temp->average;
temp->number=ps->number;
temp->name=ps->name;
temp->math=ps->math;
temp->english=ps->english;
temp->china=ps->china
temp->average=ps->average;
ps->number=tempdate->number;
ps->name=tempdate->name;
ps->math=tempdate->math;
ps->english=tempdate->english;
ps->china=tempdate->china;
ps->average=tempdate->average;
}
}
return head;
}
list head;//定义一个全局变量
void main()
{
int ch,N,num;
list pass;
printf("欢迎使用学生管理系统");
printf("********************");
printf("1:输入学生成绩");
printf("2:插入学成绩");
printf("3:删除学生成绩");
printf("4:退出系统");
printf("********************")
scanf("%d",&ch);
switch(ch)
case 1:{printf("请输入要输入的学生数");
scanf("%d",&N);
head=head(int N);//输入
order_list(list head);//排序
prinf_student(list head);//打印
break;
}
case 2:{
pss=(list)malloc(LEN);
insert_student(list pss,list head);
break;
}
case 3:{ printf("请输入学号");
scanf("%d",&num);
delete_student(int num,list head);
prinf_student(list head);
}
case 4:{
exit(0);
}
}
}