if(i==0){
p=(Lstu*)malloc(sizeof(Lstu));
printf("请输入第%d个人的信息\n",i+1);
printf("请输入班级:
");scanf("%d",&p->cla);
printf("请输入学号:
");scanf("%ld",&p->num);
printf("请输入姓名:
");scanf("%s",p->name);
printf("请输入性别:
");scanf("%s",p->sex);
printf("请输入语文成绩:
");scanf("%f",&p->chinese);
printf("请输入数学成绩:
");scanf("%f",&p->math);
printf("请输入英语成绩:
");scanf("%f",&p->english);
p->sum=p->chinese+p->math+p->english;
p->ave=p->sum/3;
head=p;
if(n==1){
p->next=NULL;}}
else{
s=(Lstu*)malloc(sizeof(Lstu));
printf("请输入第%d个人的信息\n",i+1);
printf("请输入班级:
");scanf("%d",&s->cla);
printf("请输入学号:
");scanf("%ld",&s->num);
printf("请输入姓名:
");scanf("%s",s->name);
printf("请输入性别:
");scanf("%s",s->sex);
printf("请输入语文成绩:
");scanf("%f",&s->chinese);
printf("请输入数学成绩:
");scanf("%f",&s->math);
printf("请输入英语成绩:
");scanf("%f",&s->english);
s->sum=s->chinese+s->math+s->english;
s->ave=s->sum/3;
p->next=s;p=s;
s->next=NULL;}
}
}
voidList(){//输出链表内容
Lstu*p;
inti=0;
p=head;
if(p==NULL){
printf("Sorry,It'saEmptyList\n");}
else{
printf("\n\n\t------------------------------------------------------------------\n");
printf("\t%-5s%-5s%-10s%-8s%-7s%-10s%-10s%-10s\n","序号","班级","学号","姓名","性别","语文成绩","数学成绩","英语成绩");
printf("\t------------------------------------------------------------------\n");
while(p){i++;p->ID=i;
printf("\t%-4d%-5d%-7d%-8s%-7s%-10.2f%-10.2f%-10.2f\n",p->ID,p->cla,p->num,p->name,p->sex,p->chinese,p->math,p->english);
printf("\t------------------------------------------------------------------\n");
p=p->next;
}
}
}
voidlist(){//输出链表所有内容
Lstu*p;
inti=0;
p=head;
if(p==NULL){
printf("Sorry,It'saEmptyList\n");}
else{
printf("\n----------------------------------------------------------------------------------\n");
printf("%-5s%-5s%-7s%-8s%-7s%-10s%-10s%-10s%-8s%-8s\n","序号","班级","学号","姓名","性别","语文成绩","数学成绩",
"英语成绩","总分","平均分");
printf("----------------------------------------------------------------------------------\n");
while(p){i++;p->ID=i;
printf("%-4d%-6d%-12d%-8s%-7s%-10.2f%-10.2f%-10.2f%-8.2f%-8.2f\n",p->ID,p->cla,p->num,p->name,p->sex,
p->chinese,p->math,p->english,p->sum,p->ave);
printf("----------------------------------------------------------------------------------\n");
p=p->next;
}
}
}
voidsave(){//文件保存
FILE*fp;
Lstu*p;
p=head;
if((fp=fopen("初始值二进制.txt","wb"))==NULL)
{
printf("Cannotopenthefile");
exit(0);
}
while(p){
fwrite(p,sizeof(Lstu),1,fp);
p=p->next;}
fclose(fp);
}
voidsave1(){//文件保存
FILE*fp;
Lstu*p;
p=head;
if((fp=fopen("初始值二进制备用.txt","wb"))==NULL)
{
printf("Cannotopenthefile");
exit(0);
}
while(p){
fwrite(p,sizeof(Lstu),1,fp);
p=p->next;}
fclose(fp);
}
voidread(){//文件读取
FILE*fp;
Lstu*p,*p1;
if((fp=fopen("初始值二进制.txt","rb"))==NULL)
{
printf("Cannotopenthefile\n");
exit(0);
}head=(Lstu*)malloc(sizeof(Lstu));
p1=head;
while(!
feof(fp)){
p=(Lstu*)malloc(sizeof(Lstu));
if(fread(p,sizeof(Lstu),1,fp)==1)
{
p1->next=p;
p1=p1->next;
}
}head=head->next;fclose(fp);
}
voidread1(){//文件读取
FILE*fp;
Lstu*p,*p1;
if((fp=fopen("初始值二进制备用.txt","rb"))==NULL)
{
printf("Cannotopenthefile\n");
exit(0);
}head=(Lstu*)malloc(sizeof(Lstu));
p1=head;
while(!
feof(fp)){
p=(Lstu*)malloc(sizeof(Lstu));
if(fread(p,sizeof(Lstu),1,fp)==1)
{
p1->next=p;
p1=p1->next;
}
}head=head->next;fclose(fp);
}
voidSAVE(){//保存到可浏览文件
FILE*fp;
Lstu*p;inti=0;
p=head;
if((fp=fopen("初始值可浏览文件.txt","w+"))==NULL)
{
printf("Cannotopenthefile");
exit(0);
}
fprintf(fp,"\n\n\t------------------------------------------------------------------\n");
fprintf(fp,"\t%-5s%-5s%-10s%-8s%-7s%-10s%-10s%-10s\n","序号","班级","学号","姓名","性别","语文成绩","数学成绩","英语成绩");
fprintf(fp,"\t------------------------------------------------------------------\n\n");
while(p){
i++;p->ID=i;
fprintf(fp,"\t%-4d%-5d%-7d%-8s%-7s%-10.2f%-10.2f%-10.2f\n",p->ID,p->cla,p->num,p->name,
p->sex,p->chinese,p->math,p->english);
fprintf(fp,"\t------------------------------------------------------------------\n");
p=p->next;
}
fclose(fp);
}
voidSAVE1(){//保存到可浏览文件
FILE*fp;charfilename[20];
Lstu*p;inti=0;
p=head;
printf("请输入保存到可浏览文件的文件名:
");
scanf("%s",filename);
if((fp=fopen(filename,"w+"))==NULL)
{
printf("Cannotopenthefile");
exit(0);
}
fprintf(fp,"\n----------------------------------------------------------------------------------\n");
fprintf(fp,"%-5s%-5s%-7s%-8s%-7s%-10s%-10s%-10s%-8s%-8s\n","序号","班级","学号","姓名","性别","语文成绩","数学成绩",
"英语成绩","总分","平均分");
fprintf(fp,"----------------------------------------------------------------------------------\n");
while(p){
i++;p->ID=i;
fprintf(fp,"%-4d%-5d%-7d%-8s%-7s%-10.2f%-10.2f%-10.2f%-8.2f%-8.2f\n",p->ID,p->cla,p->num,p->name,p->sex,
p->chinese,p->math,p->english,p->sum,p->ave);
fprintf(fp,"-------------------------------------------------------------------------------\n");
p=p->next;
}
fclose(fp);
}
voidsort_data_copy(Lstu*p,Lstu*s){//交换排序时的值
intcla1;
cla1=p->cla;p->cla=s->cla;s->cla=cla1;
longnum1;
num1=p->num;p->num=s->num;s->num=num1;
charname1[20];
strcpy(name1,p->name);strcpy(p->name,s->name);strcpy(s->name,name1);
charsex1[20];
strcpy(sex1,p->sex);strcpy(p->sex,s->sex);strcpy(s->sex,sex1);
floatchinese1;
chinese1=p->chinese;p->chinese=s->chinese;s->chinese=chinese1;
floatmath1;
math1=p->math;p->math=s->math;s->math=math1;
floatenglish1;
english1=p->english;p->english=s->english;s->english=english1;
floatsum1;
sum1=p->sum;p->sum=s->sum;s->sum=sum1;
floatave1;
ave1=p->ave;p->ave=s->ave;s->ave=ave1;
}
voidsort(){//对初始成绩进行排序
Lstu*p,*s;
intn;chara;
read();p=head;
if(p==NULL){
printf("Sorry,It'saEmptyList\n");
printf("\n按Enter键继续\n");a=getch();}
else{while
(1){system("cls");printf("\n排序前结果为:
\n");read();list();
printf("\t*=*=*=*=*=*=*=*=*=*=*=按学号排序
(1)\n");
printf("\t*=*=*=*=*=*=*=*=*=*=*=按语文成绩排序
(2)\n");
printf("\t*=*=*=*=*=*=*=*=*=*=*=按数学成绩排序(3)\n");
printf("\t*=*=*=*=*=*=*=*=*=*=*=按英语成绩排序(4)\n");
printf("\t*=*=*=*=*=*=*=*=*=*=*=按平均分排序(5)\