c學生成績排序鏈表
『壹』 以下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語言的最新標准,該標准更好的支持了漢字函數名和漢字標識符,一定程度上實現了漢字編程。