当前位置:首页 » 考试成绩 » c学生成绩排序链表

c学生成绩排序链表

发布时间: 2020-12-14 19:55:57

『壹』 以下c语言菜单(关于使用链表排序成绩)如何改动

你的代码不全,看不到具体链表构建。
从现有代码看:
1、建议结构指针初始化版NULL(习惯)。struct person *head=NULL,*head1=NULL;
2、既然你定义权了头指针head,正常习惯头指针是不存放数据的,只是next指向链表第一个节点。那么循环链表那里应该写while(p->next)而不是while(p!=NULL)。(除非你的head就是第一个节点)。
3、如像我上条所述,head是头指针,循环改成while(p->next),那么链表冒泡排序那里,p1=p->next;可以写p1=p->next->next;(当然你写p1=p->next;也不错,就是循环次数多点)

『贰』 急求,C语言学生管理系统一部分,链表排序的问题

voidBubbleSort(structstudent*head){
回structstudent*p,*q,*pt;
for(p=head;p->next;p=p->next){
答q=p->next;
while(q->next){
if(p->next->grade<q->next->grade){
pt=p->next;
p->next=q->next;
q->next=p->next->next;
p->next->next=pt;
}
elseq=q->next;
}
}
}

『叁』 C语言链表按学号排序,不用递归,大哥大姐指点

这是个啥??

『肆』 C语言链表中如何实现对一组数据进行排序

#include<stdio.h>
#include<stdlib.h>
#define NULL 0
struct student * creat();
struct student * link(struct student * head_a,struct student * head_b);
void print(struct student * head);
struct student{
int num;
float score[2];
struct student *next;
}stu;
int main(void)
{
struct student *head_a;
struct student *head_b,*head_c;
printf("请输入a链表学生的数据: 0 0结束输入\n");
head_a=creat();
print(head_a);
printf("请输入b链表学生的数据:0 0 0结束输入\n");
head_b=creat();
print(head_b);
head_c=link(head_a,head_b);
printf("打印经过排序之后的学生数据,a,b链数据的结合\n");
print(head_c);
return 0;
}

struct student * creat()
{
int n=0;
struct student * head,*p1,*p2;
p1=p2=(struct student *)malloc(sizeof(struct student ));
scanf("%d%f%f",&p1->num,&p1->score[0],&p1->score[1]);
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(sizeof(struct student));
scanf("%d%f%f",&p1->num,&p1->score[0],&p1->score[1]);
}
p2->next=NULL;
return head;
}

void print(struct student * head)
{
struct student *p;
p=head;
while(p!=NULL)
{
printf("%-10d%-10.1f%-10.1f\n",p->num,p->score[0],p->score[1]);
p=p->next;
}
return ;

}

struct student * link(struct student * head_a,struct student * head_b)
{
int n,m;
m=n=0;
struct student * head,*p1,*p2,*p3,*q;//q是在冒泡排序是(共需N-1趟排序)每趟的最后一次指针p1的位置,开始时q为Null
p1=head_a;
p2=head_b;
head=head_a;

while(p1->next!=NULL)
{p1=p1->next;n++;}
p1->next=p2;
p1=head_a;
while(p1!=NULL)
{
p1=p1->next;
n++; //n是计算链表的节点数,以备后面的排序用
}
q=NULL;
p1=head_a;
p2=p1->next ;
while(m<n)
{
m++;
//以下是采用冒泡法进行排序
while(p2!=q)
{
if(p1->num>p2->num)
{
if(head==p1) head=p2;
else p3->next=p2;
p1->next=p2->next;p2->next=p1;
//以下是按照 p3 p1 p2排序
p3=p2;p2=p1->next;
}
else
{
p3=p1;p1=p1->next;p2=p2->next;
}
}
q=p1;p1=head;p2=p1->next;
}
return (head);
}

『伍』 C语言 建立一个动态学生成绩的链表,

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int shoudsave=0; /* */
struct student
{
char() num[10];/* 学号 */
char() name[20];
char() sex[4];
int cgrade;
int mgrade;
int egrade;
int totle;
int ave;
char neartime[10];/* 最近更新时间 */
};

typedef struct node
{
struct student data;
struct node *next;
}Node,*Link;

void menu()
{
printf("********************************************************************************");
printf("\t1登记学生资料\t\t\t\t\t2删除学生资料\n");
printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n");
printf("\t5保存学生资料\t\t\t\t\t0退出系统\n");
printf("********************************************************************************\n");
}

void printstart()
{
printf("-----------------------------------------------------------------------\n");
}
void Wrong()
{
printf("\n=====>提示:输入错误!\n");
}

void Nofind()
{
printf("\n=====>提示:没有找到该学生!\n");
}

void printc() /* 本函数用于输出中文 */
{
printf(" 学号\t 姓名 性别 英语成绩 数学成绩 C语言成绩 总分 平均分\n");
}

void printe(Node *p)/* 本函数用于输出英文 */
{
printf("%-12s%s\t%s\t%d\t%d\t%d\t %d\t %d\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.totle,p->data.ave);
}

Node* Locate(Link l,char findmess[],char nameornum[]) /* 该函数用于定位连表中符合要求的接点,并返回该指针 */
{
Node *r;
if(strcmp(nameornum,"num")==0) /* 按学号查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.num,findmess)==0)
return r;
r=r->next;
}
}
else if(strcmp(nameornum,"name")==0) /* 按姓名查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.name,findmess)==0)
return r;
r=r->next;
}
}
return 0;
}

void Add(Link l) /* 增加学生 */
{
Node *p,*r,*s;
char num[10];
r=l;
s=l->next;
while(r->next!=NULL)
r=r->next; /* 将指针置于最末尾 */
while(1)
{
printf("请你输入学号(以'0'返回上一级菜单:)");
scanf("%s",num);
if(strcmp(num,"0")==0)
break;
while(s)
{
if(strcmp(s->data.num,num)==0)
{
printf("=====>提示:学号为'%s'的学生已经存在,若要修改请你选择'4 修改'!\n",num);
printstart();
printc();
printe(s);
printstart();
printf("\n");
return;
}
s=s->next;
}

p=(Node *)malloc(sizeof(Node));

strcpy(p->data.num,num);
printf("请你输入姓名:");
scanf("%s",p->data.name);
getchar()();
printf("请你输入性别:");
scanf("%s",p->data.sex);
getchar()();
printf("请你输入c语言成绩:");
scanf("%d",&p->data.cgrade);
getchar()();
printf("请你输入数学成绩:");
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入英语成绩:");
scanf("%d",&p->data.egrade);
getchar();
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle / 3;
/* 信息输入已经完成 */
p->next=NULL;
r->next=p;
r=p;
shoudsave=1;

}
}

void Qur(Link l) /* 查询学生 */
{
int sel;
char findmess[20];
Node *p;

if(!l->next)
{
printf("\n=====>提示:没有资料可以查询!\n");
return;

}
printf("\n=====>1按学号查找\n=====>2按姓名查找\n");
scanf("%d",&sel);
if(sel==1)/* 学号 */
{
printf("请你输入要查找的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else if(sel==2) /* 姓名 */
{
printf("请你输入要查找的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else
Wrong();

}

void Del(Link l) /* 删除 */
{
int sel;
Node *p,*r;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以删除!\n");
return;
}
printf("\n=====>1按学号删除\n=====>2按姓名删除\n");
scanf("%d",&sel);
if(sel==1)
{
printf("请你输入要删除的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else if(sel==2)
{
printf("请你输入要删除的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else
Wrong();
}

void Modify(Link l)
{
Node *p;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以修改!\n");
return;
}
printf("请你输入要修改的学生学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("请你输入新学号(原来是%s):",p->data.num);
scanf("%s",p->data.num);
printf("请你输入新姓名(原来是%s):",p->data.name);
scanf("%s",p->data.name);
getchar();
printf("请你输入新性别(原来是%s):",p->data.sex);
scanf("%s",p->data.sex);
printf("请你输入新的c语言成绩(原来是%d分):",p->data.cgrade);
scanf("%d",&p->data.cgrade);
getchar();
printf("请你输入新的数学成绩(原来是%d分):",p->data.mgrade);
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入新的英语成绩(原来是%d分):",p->data.egrade);
scanf("%d",&p->data.egrade);
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle/3;
printf("\n=====>提示:资料修改成功!\n");
shoudsave=1;
}
else
Nofind();

}

void Disp(Link l)
{
int count=0;
Node *p;
p=l->next;

if(!p)
{
printf("\n=====>提示:没有资料可以显示!\n");
return;
}
printf("\t\t\t\t显示结果\n");
printstart();
printc();
printf("\n");
while(p)
{
printe(p);
p=p->next;
}
printstart();
printf("\n");
}

void Tongji(Link l)
{
Node *pm,*pe,*pc,*pt,*pa; /* 用于指向分数最高的接点 */
Node *r=l->next;
if(!r)
{
printf("\n=====>提示:没有资料可以统计!\n");
return ;
}
pm=pe=pc=pt=pa=r;
while(r!=NULL)
{
if(r->data.cgrade>=pc->data.cgrade)
pc=r;
if(r->data.mgrade>=pm->data.mgrade)
pm=r;
if(r->data.egrade>=pe->data.egrade)
pe=r;
if(r->data.totle>=pt->data.totle)
pt=r;
if(r->data.ave>=pa->data.ave)
pa=r;

r=r->next;
}
printf("------------------------------统计结果--------------------------------\n");
printf("总分最高者:\t%s %d分\n",pt->data.name,pt->data.totle);
printf("平均分最高者:\t%s %d分\n",pa->data.name,pa->data.ave);

printf("英语最高者:\t%s %d分\n",pe->data.name,pe->data.egrade);
printf("数学最高者:\t%s %d分\n",pm->data.name,pm->data.mgrade);
printf("c语言最高者:\t%s %d分\n",pc->data.name,pc->data.cgrade);
printstart();
}

void Sort(Link l)
{
Link ll;
Node *p,*rr,*s;

ll=(Link)malloc(sizeof(Node)); /* 用于做新的连表 */
ll->next=NULL;

if(l->next==NULL)
{
printf("\n=====>提示:没有资料可以排序!\n");
return ;
}
p=l->next;
while(p)
{
s=(Node*)malloc(sizeof(Node)); /* 新建接点用于保存信息 */
s->data=p->data;
s->next=NULL;

rr=ll;
while(rr->next!=NULL && rr->next->data.totle>=p->data.totle)
rr=rr->next;
if(rr->next==NULL)
rr->next=s;
else
{
s->next=rr->next;
rr->next=s;
}
p=p->next;
}
free(l);
l->next=ll->next;
printf("\n=====>提示:排序已经完成!\n");
}

void Save(Link l)
{
FILE* fp;
Node *p;
int flag=1,count=0;
fp=fopen("c:\\student","wb");
if(fp==NULL)
{
printf("\n=====>提示:重新打开文件时发生错误!\n");
exit(1);
}
p=l->next;

while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{
p=p->next;
count++;
}
else
{
flag=0;
break;
}
}
if(flag)
{
printf("\n=====>提示:文件保存成功.(有%d条记录已经保存.)\n",count);
shoudsave=0;
}
fclose(fp);
}

void main()
{
Link l;/* 连表 */
FILE *fp; /* 文件指针 */
int sel;
char ch;
char jian;

int count=0;
Node *p,*r;
printf("\t\t\t\t学生成绩管理系统\n\t\t\t\t-------福建农业职业学院计应0501 黄欢(32号)\n");
l=(Node*)malloc(sizeof(Node));
l->next=NULL;
r=l;

fp=fopen("C:\\student","rb");
if(fp==NULL)
{
printf("\n=====>提示:文件还不存在,是否创建?(y/n)\n");
scanf("%c",&jian);
if(jian=='y'||jian=='Y')
fp=fopen("C:\\student","wb");
else
exit(0);
}
printf("\n=====>提示:文件已经打开,正在导入记录......\n");

while(!feof(fp))
{
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp)) /* 将文件的内容放入接点中 */
{
p->next=NULL;
r->next=p;
r=p; /* 将该接点挂入连中 */
count++;
}
}

fclose(fp); /* 关闭文件 */
printf("\n=====>提示:记录导入完毕,共导入%d条记录.\n",count);

while(1)
{
menu();
printf("请你选择操作:");
scanf("%d",&sel);

if(sel==0)
{
if(shoudsave==1)
{ getchar();
printf("\n=====>提示:资料已经改动,是否将改动保存到文件中(y/n)?\n");
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
Save(l);
}
printf("\n=====>提示:你已经退出系统,再见!\n");
break;
}
switch(sel)
{
case 1:Add(l);break; /* 增加学生 */
case 2:Del(l);break;/* 删除学生 */
case 3:Qur(l);break;/* 查询学生 */
case 4:Modify(l);break;/* 修改学生 */
case 5:Save(l);break;/* 保存学生 */
case 9:printf("\t\t\t==========帮助信息==========\n");break;
default: Wrong();getchar();break;
}
}
}

『陆』 C语言链表排序

#include"stdafx.h"

#include<stdlib.h>

//创建一个节点,data为value,指向NULL

Node*Create(intvalue){

Node*head=(Node*)malloc(sizeof(Node));

head->data=value;

head->next=NULL;

returnhead;

//销毁链表

boolDestroy_List(Node*head){

Node*temp;

while(head){

temp=head->next;

free(head);

head=temp;

head=NULL;

returntrue;

//表后添加一个节点,Create(value)

boolAppend(Node*head,intvalue){

Node*n=Create(value);

Node*temp=head;

while(temp->next){

temp=temp->next;

temp->next=n;

return0;

//打印链表

voidPrint_List(Node*head){

Node*temp=head->next;

while(temp){

printf("%d->",temp->data);

temp=temp->next;

printf("\n");

//在链表的第locate个节点后(头节点为0)插入创建的节点Create(value)

boolInsert_List(Node*head,intlocate,intvalue){

Node*temp=head;

Node*p;

Node*n=Create(value);

if(locate<0)

returnfalse;

while(locate--){

if(temp->next==NULL){

temp->next=Create(value);

returntrue;

temp=temp->next;

p=temp->next;

temp->next=n;

n->next=p;

returntrue;

//删除第locate个节点后(头节点为0)的节点

boolDelete_List(Node*head,intlocate){

Node*temp=head;

Node*p;

if(locate<0)

returnfalse;

while(locate--){

if(temp==NULL){

returnfalse;

temp=temp->next;

p=temp->next->next;

free(temp->next);

temp->next=NULL;

temp->next=p;

returntrue;

//获取链表长度(不包括头节点)

intSize_List(Node*head){

Node*temp=head;

intsize=0;

while(temp->next){

temp=temp->next;

size++;

returnsize;

//链表的三种排序(选择,插入,冒泡)

boolSort_List(Node*head){

intt=0;

intsize=Size_List(head);

//选择排序

/*for(Node*temp=head->next;temp!=NULL;temp=temp->next){

for(Node*p=temp;p!=NULL;p=p->next){

if(temp->data>p->data){

printf("换%d和%d\n",temp->data,p->data);

t=temp->data;

temp->data=p->data;

p->data=t;

}*/

//插入排序

/*for(Node*temp=head->next->next;temp!=NULL;temp=temp->next){

for(Node*p=head;p->next!=NULL;p=p->next){

if(p->next->data>temp->data)

printf("换%d和%d\n",temp->data,p->next->data);

t=temp->data;

temp->data=p->next->data;

p->next->data=t;

}*/

//冒泡排序

for(Node*temp=head->next;temp->next!=NULL;temp=temp->next){

for(Node*p=head->next;p->next!=NULL;p=p->next){

if(p->data>p->next->data){

t=p->data;

p->data=p->next->data;

p->next->data=t;

return0;

(6)c学生成绩排序链表扩展阅读:

return表示把程序流程从被调函数转向主调函数并把表达式的值带回主调函数,实现函数值的返回,返回时可附带一个返回值,由return后面的参数指定。

return通常是必要的,因为函数调用的时候计算结果通常是通过返回值带出的。如果函数执行不需要返回计算结果,也经常需要返回一个状态码来表示函数执行的顺利与否(-1和0就是最常用的状态码),主调函数可以通过返回值判断被调函数的执行情况。

『柒』 C语言程序设计学生成绩管理系统,要求链表

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "windows.h"
int shoudsave=0; /* */
struct student
{
char num[10];/* 学号 */
char name[20];
char sex[4];
int cgrade;
int mgrade;
int egrade;
int totle;
int ave;
char neartime[10];/* 最近更新时间 */
};
typedef struct node
{
struct student data;
struct node *next;
}Node,*Link;
void menu()
{
printf("********************************************************************************");
printf("\t1登记学生资料\t\t\t\t\t2删除学生资料\n");
printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n");
printf("\t5保存学生资料\t\t\t\t\t0退出系统\n");
printf("********************************************************************************\n");
}
void printstart()
{
printf("-----------------------------------------------------------------------\n");
}
void Wrong()
{
printf("\n=====>提示:输入错误!\n");
}
void Nofind()
{
printf("\n=====>提示:没有找到该学生!\n");
}
void printc() /* 本函数用于输出中文 */
{
printf(" 学号\t 姓名 性别 英语成绩 数学成绩 C语言成绩 总分 平均分\n");
}
void printe(Node *p)/* 本函数用于输出英文 */
{
printf("%-12s%s\t%s\t%d\t%d\t%d\t %d\t %d\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.totle,p->data.ave);
}
Node* Locate(Link l,char findmess[],char nameornum[]) /* 该函数用于定位连表中符合要求的接点,并返回该指针 */
{
Node *r;
if(strcmp(nameornum,"num")==0) /* 按学号查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.num,findmess)==0)
return r;
r=r->next;
}
}
else if(strcmp(nameornum,"name")==0) /* 按姓名查询 */
{
r=l->next;
while(r!=NULL)
{
if(strcmp(r->data.name,findmess)==0)
return r;
r=r->next;
}
}
return 0;
}
void Add(Link l) /* 增加学生 */
{
Node *p,*r,*s;
char num[10];
r=l;
s=l->next;
while(r->next!=NULL)
r=r->next; /* 将指针置于最末尾 */
while(1)
{
printf("请你输入学号(以'0'返回上一级菜单:)");
scanf("%s",num);
if(strcmp(num,"0")==0)
break;
while(s)
{
if(strcmp(s->data.num,num)==0)
{
printf("=====>提示:学号为'%s'的学生已经存在,若要修改请你选择'4 修改'!\n",num);
printstart();
printc();
printe(s);
printstart();
printf("\n");
return;
}
s=s->next;
}
p=(Node *)malloc(sizeof(Node));
strcpy(p->data.num,num);
printf("请你输入姓名:");
scanf("%s",p->data.name);
getchar();
printf("请你输入性别:");
scanf("%s",p->data.sex);
getchar();
printf("请你输入c语言成绩:");
scanf("%d",&p->data.cgrade);
getchar();
printf("请你输入数学成绩:");
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入英语成绩:");
scanf("%d",&p->data.egrade);
getchar();
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle / 3;
/* 信息输入已经完成 */
p->next=NULL;
r->next=p;
r=p;
shoudsave=1;
}
}
void Qur(Link l) /* 查询学生 */
{
int sel;
char findmess[20];
Node *p;
if(!l->next)
{
printf("\n=====>提示:没有资料可以查询!\n");
return;
}
printf("\n=====>1按学号查找\n=====>2按姓名查找\n");
scanf("%d",&sel);
if(sel==1)/* 学号 */
{
printf("请你输入要查找的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else if(sel==2) /* 姓名 */
{
printf("请你输入要查找的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
printf("\t\t\t\t查找结果\n");
printstart();
printc();
printe(p);
printstart();
}
else
Nofind();
}
else
Wrong();
}
void Del(Link l) /* 删除 */
{
int sel;
Node *p,*r;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以删除!\n");
return;
}
printf("\n=====>1按学号删除\n=====>2按姓名删除\n");
scanf("%d",&sel);
if(sel==1)
{
printf("请你输入要删除的学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else if(sel==2)
{
printf("请你输入要删除的姓名:");
scanf("%s",findmess);
p=Locate(l,findmess,"name");
if(p)
{
r=l;
while(r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>提示:该学生已经成功删除!\n");
shoudsave=1;
}
else
Nofind();
}
else
Wrong();
}
void Modify(Link l)
{
Node *p;
char findmess[20];
if(!l->next)
{
printf("\n=====>提示:没有资料可以修改!\n");
return;
}
printf("请你输入要修改的学生学号:");
scanf("%s",findmess);
p=Locate(l,findmess,"num");
if(p)
{
printf("请你输入新学号(原来是%s):",p->data.num);
scanf("%s",p->data.num);
printf("请你输入新姓名(原来是%s):",p->data.name);
scanf("%s",p->data.name);
getchar();
printf("请你输入新性别(原来是%s):",p->data.sex);
scanf("%s",p->data.sex);
printf("请你输入新的c语言成绩(原来是%d分):",p->data.cgrade);
scanf("%d",&p->data.cgrade);
getchar();
printf("请你输入新的数学成绩(原来是%d分):",p->data.mgrade);
scanf("%d",&p->data.mgrade);
getchar();
printf("请你输入新的英语成绩(原来是%d分):",p->data.egrade);
scanf("%d",&p->data.egrade);
p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;
p->data.ave=p->data.totle/3;
printf("\n=====>提示:资料修改成功!\n");
shoudsave=1;
}
else
Nofind();
}
void Disp(Link l)
{
int count=0;
Node *p;
p=l->next;
if(!p)
{
printf("\n=====>提示:没有资料可以显示!\n");
return;
}
printf("\t\t\t\t显示结果\n");
printstart();
printc();
printf("\n");
while(p)
{
printe(p);
p=p->next;
}
printstart();
printf("\n");
}
void Tongji(Link l)
{
Node *pm,*pe,*pc,*pt,*pa; /* 用于指向分数最高的接点 */
Node *r=l->next;
if(!r)
{
printf("\n=====>提示:没有资料可以统计!\n");
return ;
}
pm=pe=pc=pt=pa=r;
while(r!=NULL)
{
if(r->data.cgrade>=pc->data.cgrade)
pc=r;
if(r->data.mgrade>=pm->data.mgrade)
pm=r;
if(r->data.egrade>=pe->data.egrade)
pe=r;
if(r->data.totle>=pt->data.totle)
pt=r;
if(r->data.ave>=pa->data.ave)
pa=r;
r=r->next;
}
printf("------------------------------统计结果--------------------------------\n");
printf("总分最高者:\t%s %d分\n",pt->data.name,pt->data.totle);
printf("平均分最高者:\t%s %d分\n",pa->data.name,pa->data.ave);
printf("英语最高者:\t%s %d分\n",pe->data.name,pe->data.egrade);
printf("数学最高者:\t%s %d分\n",pm->data.name,pm->data.mgrade);
printf("c语言最高者:\t%s %d分\n",pc->data.name,pc->data.cgrade);
printstart();
}
void Sort(Link l)
{
Link ll;
Node *p,*rr,*s;
ll=(Link)malloc(sizeof(Node)); /* 用于做新的连表 */
ll->next=NULL;
if(l->next==NULL)
{
printf("\n=====>提示:没有资料可以排序!\n");
return ;
}
p=l->next;
while(p)
{
s=(Node*)malloc(sizeof(Node)); /* 新建接点用于保存信息 */
s->data=p->data;
s->next=NULL;
rr=ll;
while(rr->next!=NULL && rr->next->data.totle>=p->data.totle)
rr=rr->next;
if(rr->next==NULL)
rr->next=s;
else
{
s->next=rr->next;
rr->next=s;
}
p=p->next;
}
free(l);
l->next=ll->next;
printf("\n=====>提示:排序已经完成!\n");
}
void Save(Link l)
{
FILE* fp;
Node *p;
int flag=1,count=0;
fp=fopen("c:\\student","wb");
if(fp==NULL)
{
printf("\n=====>提示:重新打开文件时发生错误!\n");
exit(1);
}
p=l->next;
while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{
p=p->next;
count++;
}
else
{
flag=0;
break;
}
}
if(flag)
{
printf("\n=====>提示:文件保存成功.(有%d条记录已经保存.)\n",count);
shoudsave=0;
}
fclose(fp);
}
void main()
{
Link l;/* 连表 */
FILE *fp; /* 文件指针 */
int sel;
char ch;
char jian;
int count=0;
Node *p,*r;
printf("\t\t\t\t学生成绩管理系统\n\t\t\t\t----------------------实验项目\n");
l=(Node*)malloc(sizeof(Node));
l->next=NULL;
r=l;
fp=fopen("C:\\student","rb");
if(fp==NULL)
{
printf("\n=====>提示:文件还不存在,是否创建?(y/n)\n");
scanf("%c",&jian);
if(jian=='y'||jian=='Y')
fp=fopen("C:\\student","wb");
else
exit(0);
}
printf("\n=====>提示:文件已经打开,正在导入记录......\n");
while(!feof(fp))
{
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp)) /* 将文件的内容放入接点中 */
{
p->next=NULL;
r->next=p;
r=p; /* 将该接点挂入连中 */
count++;
}
}
fclose(fp); /* 关闭文件 */
printf("\n=====>提示:记录导入完毕,共导入%d条记录.\n",count);
while(1)
{
menu();
printf("请你选择操作:");
scanf("%d",&sel);
if(sel==0)
{
if(shoudsave==1)
{ getchar();
printf("\n=====>提示:资料已经改动,是否将改动保存到文件中(y/n)?\n");
scanf("%c",&ch);
if(ch=='y'||ch=='Y')
Save(l);
}
printf("\n=====>提示:你已经退出系统,再见!\n");
break;
}
switch(sel)
{
case 1:Add(l);break; /* 增加学生 */
case 2:Del(l);break;/* 删除学生 */
case 3:Qur(l);break;/* 查询学生 */
case 4:Modify(l);break;/* 修改学生 */
case 5:Save(l);break;/* 保存学生 */
case 9:printf("\t\t\t==========帮助信息==========\n");break;
default: Wrong();getchar();break;
}
}
Sleep(100);
}
/* */

『捌』 数据结构链表c语言建立学生成绩管理系统

#include<stdio.h>
#include<memory.h>
#include<stdlib.h>
#include<string.h>

typedefstructdata{
intnumber;
charname[20];
charid[20];
doublescore[3];
}dataType;

typedefstructlist{
dataTypepauline;
structlist*next;
}*LinkList,*pNode,Node;

void*getMemory(size_tsize){
returnmalloc(size);
}

LinkListgetEmptyList(){
LinkListhead=(pNode)getMemory(sizeof(Node));
memset(head,0,sizeof(Node));
returnhead;
}

intaddNode(LinkListhead,pNodepnode){
pNodeq;
for(q=head;q->next;q=q->next)
if(q->next->pauline.number==pnode->pauline.number){
printf("重复的学号:%d ",pnode->pauline.number);
return0;
}
q->next=pnode;
pnode->next=NULL;
return1;
}

//按学号升排序
voidsortNumber(LinkListhead){
pNodep,q,pt,qt;
p=head;
while(p->next){
qt=p;
q=p->next;
while(q->next){
if(qt->next->pauline.number>q->next->pauline.number)
qt=q;
q=q->next;
}
if(qt!=p){
pt=p->next;
p->next=qt->next;
qt->next=qt->next->next;
p->next->next=pt;
}
p=p->next;
}
}

//按第th门成绩降排序,th=1,2,3
voidsortScore(LinkListhead,intth){
pNodep,q,pt,qt;
inti;
if(th<1||th>3)return;
i=th-1;
for(p=head;p->next;p=p->next){
qt=p;
q=p->next;
while(q->next){
if(qt->next->pauline.score[i]<q->next->pauline.score[i])
qt=q;
q=q->next;
}
if(qt!=p){
pt=p->next;
p->next=qt->next;
qt->next=qt->next->next;
p->next->next=pt;
}
}
}

voidshow(LinkListhead){
pNodep;
for(p=head->next;p;p=p->next ){
printf("%d %s %s %.2lf %.2lf %.2lf ",
p->pauline.number,p->pauline.name,p->pauline.id,
p->pauline.score[0],p->pauline.score[1],p->pauline.score[2]);
}
}

pNodereadData(){
pNodepnode=(pNode)getMemory(sizeof(Node));
inti;
printf("学号:");
scanf("%d",&pnode->pauline.number);
printf("姓名:");
scanf("%s",pnode->pauline.name);
printf("身份证:");
scanf("%s",pnode->pauline.id);
for(i=0;i<3;++i){
printf("第%d门成绩:",i+1);
scanf("%lf",&pnode->pauline.score[i]);
}
returnpnode;
}

voidmenu(){
printf("******************************** ");
printf("******学生成绩管理系统****** ");
printf("******************************** ");
printf("*1、添加学生信息* ");
printf("*2、显示学生信息* ");
printf("*3、按学号排序* ");
printf("*4、按成绩排序* ");
printf("******************************** ");
printf("*0、退出* ");
printf("******************************** ");
}

intmain(){
charop[20];
intselect;
LinkListhead=getEmptyList();
do{
menu();
printf("请选择:");
fflush(stdin);
fgets(op,20,stdin);
fflush(stdin);
switch(op[0]-'0'){
case1:addNode(head,readData());break;
case2:show(head);break;
case3:sortNumber(head);break;
case4:printf("按第几门功课排序;");
scanf("%d",&select);
sortScore(head,select);
break;
}
}while(op[0]-'0');
printf("END ");
return0;
}

『玖』 C语言学生成绩管理系统中的链表排序怎么做

用冒泡排序!虽然效率低!比如:a[N]={3,2,5,4,2,6}for(int i = 0;i<(数组长度/2);i++) for(int j=i+1;j<数组长度;j++) if(a[i]>a[j]) { int temp = a[i]; a[i] = a[j]; a[j] = temp; }从第一个元素开始,依次往后面的元素比较,小的放前,大的放后,基本方法就这样了~!

『拾』 c语言!!!程序设计:建立一个学生信息链表,包括学号,姓名,成绩.(实现添加,删除,查询,排序,平均)

#include<iostream>

using namespace std;

struct stu{

char name[20];

int num;

int age;

char sex;

int grade;

struct stu *next;

};

struct stu *mythis,*mynew;

void newrecord(struct stu *head)

{

mythis=head->next;

while(mythis!=NULL)

mythis=mythis->next;

mynew=(struct stu *)malloc(sizeof(struct stu));

cin>>mynew->name>>mynew->num>>mynew->age>>mynew->sex>>mynew->grade;

mynew->next=NULL;

if(mythis==NULL)

{

mythis=(struct stu *)malloc(sizeof(struct stu));

mythis=mynew;

}

}

void listall(stu *head)

{

mythis=head->next;

while(mythis!=NULL)

{

cout<<mythis->name<<mythis->num<<mythis->age<<mythis->sex<<mythis->grade;

mythis=mythis->next;

}

}

int main()

{

char decide;

struct stu *head;

head=(struct stu *)malloc(sizeof(struct stu));

head->next=NULL;

while(1)

{

cout<<"Please input decide:"<<endl;

cin>>decide;

if(decide=='n')

newrecord(head);

else

if(decide=='1')

listall(head);

else

return 0;

}

}



拓展资料

C语言是一门通用计算机编程语言,应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。

尽管C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。

二十世纪八十年代,为了避免各开发厂商用的C语言语法产生差异,由美国国家标准局为C语言制定了一套完整的美国国家标准语法,称为ANSI C,作为C语言最初的标准。目前2011年12月8日,国际标准化组织(ISO)和国际电工委员会(IEC)发布的C11标准是C语言的第三个官方标准,也是C语言的最新标准,该标准更好的支持了汉字函数名和汉字标识符,一定程度上实现了汉字编程。



热点内容
武汉大学学生会辅导员寄语 发布:2021-03-16 21:44:16 浏览:612
七年级学生作文辅导学案 发布:2021-03-16 21:42:09 浏览:1
不屑弟高考成绩 发布:2021-03-16 21:40:59 浏览:754
大学毕业证会有成绩单 发布:2021-03-16 21:40:07 浏览:756
2017信阳学院辅导员招聘名单 发布:2021-03-16 21:40:02 浏览:800
查询重庆2018中考成绩查询 发布:2021-03-16 21:39:58 浏览:21
结业考试成绩怎么查询 发布:2021-03-16 21:28:40 浏览:679
14中医医师资格笔试考试成绩查分 发布:2021-03-16 21:28:39 浏览:655
名著赏析课程标准 发布:2021-03-16 21:27:57 浏览:881
北京大学商业领袖高端培训课程 发布:2021-03-16 21:27:41 浏览:919