




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、鏈表動(dòng)態(tài)創(chuàng)建#include#include#includestruct Studentchar num10; /字符串學(xué)號(hào)char name10; /字符串姓名double score; /雙精度實(shí)型成績(jī)struct Student *next; /用與構(gòu)建鏈表指向下一結(jié)點(diǎn);struct Student *creatlinklist()/當(dāng)成績(jī)項(xiàng)目輸入0時(shí),創(chuàng)建鏈表結(jié)束struct Student *head;struct Student *p1,*p2;int n;n=0;head=NULL;p1=(struct Student *)malloc(sizeof(struct Student
2、);printf(請(qǐng)輸入學(xué)號(hào)姓名和成績(jī)n);scanf(%s%s%lf,p1-num,p1-name,&p1-score);while(p1-score!=0)if(n=0)head=p1;p2=p1;n+;elsep2-next=p1;p2=p1;n+;p1=(struct Student *)malloc(sizeof(struct Student);printf(請(qǐng)輸入學(xué)號(hào)姓名和成績(jī)n);scanf(%s%s%lf,p1-num,p1-name,&p1-score);if(head!=NULL)p2-next=NULL;return head;void print_linklist(st
3、ruct Student *head)struct Student *pi;if(head=NULL)printf(空鏈表!n);elseprintf(學(xué)號(hào)t姓名t成績(jī)n);for(pi=head;pi!=NULL;pi=pi-next)printf(%st%st%lfn,pi-num,pi-name,pi-score);int main()struct Student *head;head=creatlinklist();print_linklist(head);return 0;/鏈表查找#include#include#includestruct Studentchar num10; /
4、字符串學(xué)號(hào)char name10; /字符串姓名double score; /雙精度實(shí)型成績(jī)struct Student *next; /用與構(gòu)建鏈表指向下一結(jié)點(diǎn);struct Student *creatlinklist()struct Student *head;struct Student *p1,*p2;int n;n=0;head=NULL;p1=(struct Student *)malloc(sizeof(struct Student);printf(請(qǐng)輸入學(xué)號(hào)姓名和成績(jī)n);scanf(%s%s%lf,p1-num,p1-name,&p1-score);while(p1-sco
5、re!=0)if(n=0)head=p1;p2=p1;n+;elsep2-next=p1;p2=p1;n+;p1=(struct Student *)malloc(sizeof(struct Student);printf(請(qǐng)輸入學(xué)號(hào)姓名和成績(jī)n);scanf(%s%s%lf,p1-num,p1-name,&p1-score);if(head!=NULL)p2-next=NULL;return head;void printlinklist(struct Student *head)struct Student *pi;if(head=NULL)printf(空鏈表!n);elseprintf
6、(學(xué)號(hào)t姓名t成績(jī)n);for(pi=head;pi!=NULL;pi=pi-next)printf(%st%st%lfn,pi-num,pi-name,pi-score);struct Student * find_linklist_by_name(struct Student *head,char name)struct Student *pi;struct Student *pr;pr=NULL;for(pi=head;pi!=NULL;pi=pi-next)if(strcmp(name,pi-name)=0)pr=pi;break;return pr;void print_one_no
7、de(struct Student *p)if(p=NULL)printf(查無(wú)此人n);elseprintf(學(xué)號(hào)t姓名t成績(jī)n);printf(%st%st%lfn,p-num,p-name,p-score);int main()struct Student *head;struct Student *pr;char name10;head=creatlinklist();printlinklist(head);printf(請(qǐng)輸入要查找學(xué)生的姓名n);scanf(%s,&name);pr=find_linklist_by_name(head,name);print_one_node(pr
8、);/鏈表排序#include#include#includestruct Studentchar num10; /字符串學(xué)號(hào)char name10; /字符串姓名double score; /雙精度實(shí)型成績(jī)struct Student *next; /用與構(gòu)建鏈表指向下一結(jié)點(diǎn);struct Student *creatlinklist()struct Student *head;struct Student *p1,*p2;int n;n=0;head=NULL;p1=(struct Student *)malloc(sizeof(struct Student);printf(請(qǐng)輸入學(xué)號(hào)姓名
9、和成績(jī)n);scanf(%s%s%lf,p1-num,p1-name,&p1-score);while(p1-score!=0)if(n=0)head=p1;p2=p1;n+;elsep2-next=p1;p2=p1;n+;p1=(struct Student *)malloc(sizeof(struct Student);printf(請(qǐng)輸入學(xué)號(hào)姓名和成績(jī)n);scanf(%s%s%lf,p1-num,p1-name,&p1-score);if(head!=NULL)p2-next=NULL;return head;void printlinklist(struct Student *hea
10、d)struct Student *pi;if(head=NULL)printf(空鏈表!n);elseprintf(學(xué)號(hào)t姓名t成績(jī)n);for(pi=head;pi!=NULL;pi=pi-next)printf(%st%st%lfn,pi-num,pi-name,pi-score);void select_sortlinklist_by_score(struct Student *head)struct Student *select_sortlinklist_by_score_(struct Student *head)struct Student *pi;struct Student
11、 *phead,*ptail;struct Student *pmin,*pmin0;phead=NULL;while(head!=NULL)pmin=head;for(pi=head;pi-next!=NULL;pi=pi-next)if(pi-next-javajava)pmin0=pi;pmin=pi-next;if(phead=NULL)phead=pmin;ptail=pmin;elseptail-next=pmin;ptail=pmin;if(pmin=head)head=head-next;elsepmin0-next=pmin-next;if(phead!=NULL)ptail
12、-next=NULL;return phead;int main()struct Student *head;head=creatlinklist();printlinklist(head);head=select_sortlinklist_by_score_(head);printf(按分?jǐn)?shù)排序后n);printlinklist(head);return 0;/鏈表按順序插入#include#include#includestruct Studentchar num10; /字符串學(xué)號(hào)char name10; /字符串姓名double score; /雙精度實(shí)型成績(jī)struct Studen
13、t *next; /用與構(gòu)建鏈表指向下一結(jié)點(diǎn);struct Student *creatlinklist()struct Student *head;struct Student *p1,*p2;int n;n=0;head=NULL;p1=(struct Student *)malloc(sizeof(struct Student);printf(請(qǐng)輸入學(xué)號(hào)姓名和成績(jī)n);scanf(%s%s%lf,p1-num,p1-name,&p1-score);while(p1-score!=0)if(n=0)head=p1;p2=p1;n+;elsep2-next=p1;p2=p1;n+;p1=(s
14、truct Student *)malloc(sizeof(struct Student);printf(請(qǐng)輸入學(xué)號(hào)姓名和成績(jī)n);scanf(%s%s%lf,p1-num,p1-name,&p1-score);if(head!=NULL)p2-next=NULL;return head;void printlinklist(struct Student *head)struct Student *pi;if(head=NULL)printf(空鏈表!n);elseprintf(學(xué)號(hào)t姓名t成績(jī)n);for(pi=head;pi!=NULL;pi=pi-next)printf(%st%st%l
15、fn,pi-num,pi-name,pi-score);struct Student * find_linklist_by_name(struct Student *head,char name)struct Student *pi;struct Student *pr;pr=NULL;for(pi=head;pi!=NULL;pi=pi-next)if(strcmp(name,pi-name)=0)pr=pi;break;return pr;void sortlinklist_by_score(struct Student *head)struct Student *find_linklis
16、t_tail(struct Student *head)struct Student *pi;pi=head;while(pi-next!=NULL)pi=pi-next;return pi;struct Student *select_sortlinklist_by_score_(struct Student *head)struct Student *pi;struct Student *phead,*ptail;struct Student *pmin,*pmin0;phead=NULL;while(head!=NULL)pmin=head;for(pi=head;pi-next!=NU
17、LL;pi=pi-next)if(pi-next-scorescore)pmin0=pi;pmin=pi-next;if(phead=NULL)phead=pmin;ptail=pmin;elseptail-next=pmin;ptail=pmin;if(pmin=head)head=head-next;elsepmin0-next=pmin-next;if(phead!=NULL)ptail-next=NULL;return phead;struct Student * insertlinklist_by_score(struct Student *head,struct Student *
18、p)struct Student *pi;struct Student *pfirstmax,*pfirstmax0;struct Student *ptail;struct Student *pt;head=select_sortlinklist_by_score_(head);if(head=NULL)head=p;p-next=NULL;elseptail=find_linklist_tail(head);if(p-scoreptail-score)ptail-next=p;p-next=NULL;elseif(p-scorescore)pt=head;head=p;p-next=pt;
19、elsefor(pi=head;pi-next!=NULL;pi=pi-next)if(pi-next-scorep-score)pfirstmax=pi-next;pfirstmax0=pi;break;pfirstmax0-next=p;p-next=pfirstmax;return head;int main()struct Student *head;struct Student *p1;head=creatlinklist();printlinklist(head);p1=(struct Student *)malloc(sizeof(struct Student);printf(請(qǐng)
20、輸入學(xué)號(hào)姓名和成績(jī)n);scanf(%s%s%lf,p1-num,p1-name,&p1-score);p1-next=NULL;head=insertlinklist_by_score(head,p1);printlinklist(head);return 0;/合并兩個(gè)鏈表并排序#include#include#includestruct Studentchar name20; /字符型學(xué)生姓名double java; /雙精度實(shí)型Java成績(jī)struct Student *next; /用與構(gòu)建連表指向下一結(jié)點(diǎn);struct Student *creatlinklist()struct
21、Student*head,*p1,*p2;int n;n=0;head=NULL;p1=(struct Student*)malloc(sizeof(struct Student);printf(請(qǐng)輸入姓名和java成績(jī):);scanf(%s%lf,p1-name,&p1-java);while(p1-java!=0)if(n=0)head=p1;p2=p1;n+;elsep2-next=p1;p2=p1;n+;p1=(struct Student*)malloc(sizeof(struct Student);printf(請(qǐng)輸入姓名和java成績(jī):);scanf(%s%lf,p1-name,
22、&p1-java);if(head!=NULL)p2-next=NULL;return head;void printlinklist(struct Student *head)struct Student *p;if(head=NULL)printf(姓名tjava成績(jī)n);elseprintf(姓名tjava成績(jī)n);for(p=head;p!=NULL;p=p-next)printf(%st%lfn,p-name,p-java);struct Student *select_sortlinklist_by_java(struct Student *head)struct Student *pi;struct Student *phead,*ptail;struct Student *pmin,*pmin0;phead=NULL;while(head!=NULL)pmin=head;for(pi=head;pi-next!=NULL;pi=pi-next)if(pi-next-java
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 目標(biāo)設(shè)定中的常見(jiàn)誤區(qū)考核試卷
- 學(xué)校文化氛圍對(duì)學(xué)生職業(yè)適應(yīng)能力的培養(yǎng)考核試卷
- 園林工具制造中的復(fù)合材料應(yīng)用研究考核試卷
- 風(fēng)味穩(wěn)定性考核試卷
- 光纖通信網(wǎng)絡(luò)傳輸速率標(biāo)準(zhǔn)考核試卷
- 急救知識(shí)試題庫(kù)+參考答案
- 機(jī)器人科技探索未來(lái)主題班會(huì)課件
- 低碳生活活動(dòng)總結(jié)15篇
- 每周雙講活動(dòng)方案
- 民俗開(kāi)學(xué)儀式活動(dòng)方案
- 2016-2022年全國(guó)高考英語(yǔ)讀后續(xù)寫及概要寫作試題真題及范文
- GB/T 17431.2-2010輕集料及其試驗(yàn)方法第2部分:輕集料試驗(yàn)方法
- 茶文化與茶藝實(shí)驗(yàn)指導(dǎo)書
- 第三章-液液萃取課件
- 質(zhì)量管理部半年總結(jié)PPT
- 2022年德宏傣族景頗族自治州工會(huì)系統(tǒng)招聘考試題庫(kù)及答案解析
- 雪山上的達(dá)娃讀后感范文5篇
- 安全生產(chǎn)基本情況調(diào)研表
- 西方音樂(lè)史名詞解釋復(fù)習(xí)
- 華為自評(píng)審核表 Quality System Audit
- 汽車標(biāo)準(zhǔn)件手冊(cè)
評(píng)論
0/150
提交評(píng)論