c語(yǔ)言鏈表及其相關(guān)操作代碼_第1頁(yè)
c語(yǔ)言鏈表及其相關(guān)操作代碼_第2頁(yè)
c語(yǔ)言鏈表及其相關(guān)操作代碼_第3頁(yè)
c語(yǔ)言鏈表及其相關(guān)操作代碼_第4頁(yè)
c語(yǔ)言鏈表及其相關(guān)操作代碼_第5頁(yè)
已閱讀5頁(yè),還剩9頁(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、鏈表動(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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論