雙向鏈表做學(xué)生分?jǐn)?shù)管理(共8頁(yè))_第1頁(yè)
雙向鏈表做學(xué)生分?jǐn)?shù)管理(共8頁(yè))_第2頁(yè)
雙向鏈表做學(xué)生分?jǐn)?shù)管理(共8頁(yè))_第3頁(yè)
雙向鏈表做學(xué)生分?jǐn)?shù)管理(共8頁(yè))_第4頁(yè)
雙向鏈表做學(xué)生分?jǐn)?shù)管理(共8頁(yè))_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、/*雙向循環(huán)(xnhun)鏈表的操作*/#include#include#define LEN sizeof(struct student)struct student/*雙向循環(huán)(xnhun)鏈表*/long num;float score;struct student *last, *next;/*last、next指向(zh xin)前、后一個(gè)鏈表地址*/;/*創(chuàng)建有n個(gè)節(jié)點(diǎn)的鏈表*/struct student *creat()int i, n;struct student *head, *p1, *p2; /p1當(dāng)前指針printf(n請(qǐng)輸入要?jiǎng)?chuàng)建的學(xué)生成績(jī)個(gè)數(shù)n:);scanf(%

2、d, &n);printf(n請(qǐng)輸入學(xué)號(hào) 分?jǐn)?shù)n);for (i = 0; i num, &p1-score);p2-last = NULL;p2-next = NULL;elsep1 = (struct student*)malloc(LEN);if (p1 = NULL)/*檢測(cè)動(dòng)態(tài)存儲(chǔ)空間是否開(kāi)辟成功*/printf(創(chuàng)建(chungjin)失敗n);elsescanf(%ld %f, &p1-num, &p1-score);p2-next = p1;p1-last = p2;p2 = p1;p2-next = NULL;if (i = n)/*成功(chnggng)創(chuàng)建n組數(shù)據(jù)(shj

3、)*/printf(成功創(chuàng)建%d個(gè)學(xué)生成績(jī)n, n);head-last = p2;p2-next = head;elseprintf(創(chuàng)建%d個(gè)學(xué)生成績(jī)失敗n, n);return(head);/*打印鏈表*/void print(struct student *head)struct student *p;printf(學(xué)生成績(jī)記錄為:n);printf(學(xué)號(hào) 分?jǐn)?shù)n);p = head;if (head != NULL)/*檢測(cè)當(dāng)前鏈表是否為空*/doprintf(%ld %fn, p-num, p-score);p = p-next; while (p != head);elsepri

4、ntf(沒(méi)有學(xué)生數(shù)據(jù)n);/*查詢分?jǐn)?shù)*/void search(struct student *head)struct student *p = head;long n = 0;int flag = 0;/*flag標(biāo)志(biozh)位,n需要(xyo)查詢的學(xué)號(hào)*/printf(請(qǐng)輸入(shr)要查詢學(xué)生的學(xué)號(hào):);scanf(%ld, &n);if(p=NULL)printf(這是一個(gè)空表);elsedoif (p-num = n)flag = 1;/*成功找到*/break;elseflag = 0;p = p-next; while (p != head);if (flag = 1)

5、printf(學(xué)號(hào)為%ld的學(xué)生的成績(jī)?yōu)椋?fn, n, p-score);elseprintf(沒(méi)有學(xué)號(hào)為%ld的學(xué)生的成績(jī)n, n);/*修改分?jǐn)?shù)*/void modify(struct student *head)struct student *p = head;long n = 0, flag = 0;printf(請(qǐng)輸入要修改學(xué)生的學(xué)號(hào):);scanf(%ld, &n);do /*查找需要修改的學(xué)號(hào)*/if (p-num = n)flag = 1;break;elseflag = 0;p = p-next; while (p != head);if (flag = 1)printf(

6、學(xué)號(hào)為%ld的學(xué)生(xu sheng)的當(dāng)前成績(jī)?yōu)椋?fn, n, p-score);printf(請(qǐng)輸入修改(xigi)后的學(xué)生成績(jī)score:);scanf(%f, &p-score);printf(修改(xigi)后學(xué)號(hào)為%ld的學(xué)生的成績(jī)?yōu)椋?fn, n, p-score);elseprintf(沒(méi)有學(xué)號(hào)為%ld的學(xué)生的數(shù)據(jù)n, n);/*插入數(shù)據(jù)*/struct student *insert(struct student *head)struct student *p1, *p2, *p = head;long n;int flag = 0, fangshi = 0;/*flag查

7、找標(biāo)志位,m為0在表頭插入,m為1在學(xué)號(hào)n后插入*/loop:printf(fangshi為0在表頭插入,fangshi為1在學(xué)號(hào)n后插入。請(qǐng)輸入fangshi:);scanf(%d, &fangshi);if(head=NULL)printf(此表為空表,請(qǐng)先創(chuàng)建一個(gè)表格);elseswitch (fangshi)case 1:printf(請(qǐng)輸入要在哪個(gè)學(xué)號(hào)后插入數(shù)據(jù)n:);scanf(%ld,&n);do /*查找要插入數(shù)據(jù)的前一個(gè)學(xué)號(hào)*/if (p-num = n)/*p為當(dāng)前指針*/flag = 1;break;elseflag = 0;p = p-next; while (p !=

8、 head);if (flag = 1)p1 = p;/*p1指向要插入(ch r)數(shù)據(jù)的前一個(gè)首地址*/p2 = p-next;/*p2指向要插入數(shù)據(jù)(shj)的后一個(gè)首地址*/p = (struct student*)malloc(LEN);/*p為當(dāng)前開(kāi)辟的動(dòng)態(tài)(dngti)存儲(chǔ)空間首地址*/if (p = NULL)/*檢測(cè)動(dòng)態(tài)存儲(chǔ)空間是否開(kāi)辟成功*/printf(插入失敗n);elseprintf(請(qǐng)輸入要插入的學(xué)號(hào)和分?jǐn)?shù)n);scanf(%ld %f, &p-num, &p-score);p1-next=p;p-last = p1;p-next = p2;p2-last=p;pri

9、ntf(插入成功n);elseprintf(沒(méi)有找到學(xué)號(hào)為%ld的學(xué)生n,n);return(head);case 0:p2 = head;p1 = head-last;p = (struct student*)malloc(LEN);if (p = NULL)/*檢測(cè)動(dòng)態(tài)存儲(chǔ)空間是否開(kāi)辟成功*/printf(插入失敗n);elseprintf(請(qǐng)輸入要插入的學(xué)號(hào)和分?jǐn)?shù)n);scanf(%ld %f, &p-num, &p-score);head = p;p1-next = p;p-last = p1;p-next = p2;p2-last=p;printf(插入成功n);return(hea

10、d);default:printf(m值為0或1,請(qǐng)重新(chngxn)輸入n);goto loop;return(head);/*刪除(shnch)數(shù)據(jù)*/struct student *del(struct student *he)struct student *p, *p1,*p2;long n;printf(請(qǐng)輸入(shr)要?jiǎng)h除的學(xué)生的學(xué)號(hào):);scanf(%ld,&n);if (he = NULL)printf(這是一個(gè)空表);elsep = he;while (n!=p-num&p-next!=he)/*p遍歷一遍定位到要?jiǎng)h除的數(shù)據(jù)處*/p = p-next;if (n = p-

11、num)/*找到了*/p2 = p-next;p1 = p-last;p1-next = p2;p2-last = p1;if (p = he)he = p2;free(p);printf(學(xué)號(hào)為%ld的學(xué)生成績(jī)刪除成功n, n);elseprintf(學(xué)號(hào)為%ld的學(xué)生成績(jī)沒(méi)有被找到n, n);return he;/*連續(xù)在尾部添加n個(gè)數(shù)*/struct student * lianjia(struct student *he)int n,i;struct student *p1,*p2;p2=he-last;printf(請(qǐng)輸入要在尾部(wi b)添加n個(gè)學(xué)生(xu sheng)成績(jī)n=:

12、n);scanf(%d,&n);printf(n請(qǐng)輸入(shr)學(xué)號(hào) 分?jǐn)?shù)n);for(i=1;inum, &p1-score);p2-next = p1;p1-last = p2;p2 = p1;p2-next = NULL;if (i = n)/添加n個(gè)學(xué)生的成績(jī)printf(成功添加%d個(gè)學(xué)生成績(jī)n, n);he-last = p2;p2-next = he;return he;int main()int n;struct student *head;head = NULL;while (1)printf(n請(qǐng)選擇功能菜單:n);printf(1:創(chuàng)建(chungjin)一個(gè)成績(jī)表;n2

13、:插入一個(gè)學(xué)生(xu sheng)數(shù)據(jù);n3:刪除(shnch)一個(gè)學(xué)生數(shù)據(jù);n4:查詢一個(gè)學(xué)生成績(jī);n5:修改一個(gè)學(xué)生的成績(jī);n6:顯示所有成績(jī);n7:退出;n8:在尾部添加一些學(xué)生的成績(jī);n);printf(請(qǐng)輸入菜單功能數(shù)字代碼n:);scanf(%d, &n);switch (n)case 1:head = creat();break;case 2:head = insert(head);break;case 3:head = del(head);break;case 4:search(head);break;case 5:modify(head);break;case 6:print(head);break;case 7:return 0;case 8:head=lianjia(

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論