stu *del(stu*head){//根據學號刪除
stu *p,*q;// 帶頭節點的int n;printf("請輸入要刪除學生的學號:\n");scanf("%d",&n);
q = head;
p = q->next;while(p !=NULL&&p->num != n){
q = p;
p = p->next;}if(p !=NULL){
q->next = p->next;free(p);printf("刪除成功!\n");}else{printf("沒有此人!\n");}return head;}
stu *revise(stu*head){//根據學號修改
stu *p,*q;int n;
q = head;
p = q->next;printf("請輸入要修改的學生的學號:\n");scanf("%d",&n);while(p !=NULL&&p->num != n){
q = p;
p = p->next;}if(p !=NULL){
p->num = n;printf("輸入姓名:\n");scanf("%s", p->name);printf("輸入分數:\n");scanf("%d",&p->score);printf("修改成功!\n");}else{printf("沒有此人!\n");}return head;}
stu *find(stu*head){//yes
stu*p;int n;
p = head;
p = p->next;printf("請輸入要查詢的學生學號:\n");scanf("%d",&n);while(p&&p->num!=n){
p = p->next;}if(p){printf("學號:%d\n", p->num);printf("姓名:%s\n", p->name);printf("分數:%d\n", p->score);}elseprintf("沒有此人!\n");return head;}
voidshuchu(stu*haed){//傳指標 輸出連結串列printf("全部資料:\n");
stu *p;
p = haed->next;printf("學號\t姓名\t分數\n");while(p !=NULL){printf("%d\t%s\t%d\n", p->num,p->name,p->score);
p = p->next;}}
voidsa(stu*head){//檔案
FILE *fp;if((fp=fopen("abc.txt","w"))==NULL)//只寫方式{printf("cuowu打不開檔案");system("pause");}
stu *p;
p = head->next;while(p !=NULL){fprintf(fp,"%d %s %d\n",p->num,p->name,p->score);
p = p->next;}fclose(fp);}
intmain(int argc,char** argv){int a =0;readfile(m);while(1){meau();printf("請輸入命令:\n");scanf("%d",&a);switch(a){case1:sort(m);//排序break;case2:headinsert(m);//頭插法break;case3:del(m);//刪除break;case4:revise(m);//修改break;case5:find(m);//查詢break;case6:shuchu(m);//輸出break;case7:sa(m);//儲存到檔案,w形式開啟exit(0);break;}system("pause");system("cls");}return0;}