




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、v1.0可編輯可修改/*單鏈表的各種操作*/#in elude <>#in elude <>#defi ne null 0typedef int ElemType; /*字符型數(shù)據(jù) */struct LNodeElemType data;struct LNode *n ext;;void set null(struct LNode *p);int len gth (struct LNode *p);ElemType get(struct LNode *p,i nt i);void in sert(struct LNode *p,ElemType x,i nt i);vo
2、id dele(struct LNode *p,i nt i);void display(struct LNode *p);int locate(struct LNode *p,ElemType x);void mai n()struct LNode *head,*q; /*定義靜態(tài)變量*/int select,x1,x2,x3,x4;int i,n;int m,g;char e,y;setnull(&head); /*建設(shè)鏈表并設(shè)置為空表 */printf("請輸入數(shù)據(jù)長度:");sca nf("%d",&n);for(i=1;i<
3、;=n ;i+)printf(" 將數(shù)據(jù)插入到單鏈表中:");sca nf("%d", &y); in sert (&head,y,i); /*插入數(shù)據(jù)到鏈表display (&head);prin tf("select 1prin tf("select 2prin tf("select 3prin tf("select 4*/*顯示鏈表所有數(shù)據(jù)*/求長度 len gth()n"); 取結(jié)點 get()n"); 求值查找 locate()n"); 刪除結(jié)點 de
4、lete()n"); 退出n");prin tf("select 0 prin tf("i nput your select:");sca nf("%d", &select);while(select!=O)switch(select)case 1:x1=le ngth(&head);printf(" 輸出單鏈表的長度 %d ",x1);display (&head);break;case 2:printf(”請輸入要取得結(jié)點:");sca nf("%d&quo
5、t;,&m);x2=get (&head,m);prin tf("%d",x2);display (&head);break;case 3:printf(”請輸入要查找的數(shù)據(jù):");sca nf("%d", &e);x3=locate(&head,e);5is。a)s03p%vueos 廠 4。a)snoA 4nduc4u 一dFc一田密 CLA¥o)a)p<>建葷 =50io-徑wl迥錢 Fc一0056<>畀 Fc一(£6U2 鰹來錢0 4。0)3匸
6、3;d 寸4。0)3匸£d0 4。0)3匸 £d<N4。0)3匸 £d 二。0)3匸 u一dee 一l03)Ae-ds 一 p 5p03¥o)p M603p%ueos Ml 旨 u一d-寸Seo 三eaiq宀 ee 一l03)Ae-ds 一 pxp%vc_dv1.0可編輯可修改void set null(struct LNode *p)*p=n ull;int len gth (struct LNode *p)int n=0;struct LNode *q=*p;while (q!=n ull)n+;q=q->n ext;return( n)
7、;ElemType get(struct LNode *p,i nt i)in t j=1;struct LNode *q=*p;9v1.0可編輯可修改while (j<i&&q!=null)q=q->n ext;j+;if(q!=null)return(q->data);elseprintf("位置參數(shù)不正確!n");return 0; int locate(struct LNode *p,ElemType x) int n=0;struct LNode *q=*p;while (q!=n ull&&q->data!
8、=x)n+;if(q=n ull) return(-1);elsereturn( n+1); void in sert(struct LNode *p,ElemType x,i nt i)in t j=1;struct LNode *s,*q;s=(struct LNode *)malloc(sizeof(struct LNode);s->data=x;q=*p;if(i=1)s->n ext=q;*p=s;elsewhile(j<i-1 &&q->n ext!=null)11v1.0可編輯可修改q=q->n ext;j+;if(j=i-1)s-&
9、gt;n ext=q->next;q->n ext=s;elseprintf(" 位置參數(shù)不正確!n");void dele(struct LNode *p,i nt i)in t j=1;struct LNode *q=*p,*t;if(i=1)t=q;*p=q->n ext;12v1.0可編輯可修改elsewhile(j<i-1 &&q->n ext!=null)q=q->n ext;j+;if(q->next!=null&&j=i-1)t=q->n ext;q->n ext=t->next;elseprintf("位置參數(shù)不正確!n");if(t!=null)free(t);void display(struct LNode *p)struct LNode *q;q=*P;printf("單鏈表顯示:");if(q=n ull)printf("鏈表為空!");else if (q->n ext=n ull)prin tf("%dn",q
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年服裝、鞋帽加工機械項目建議書
- 2025年種植施肥機械項目合作計劃書
- 2025年C301-I型低壓甲醇合成催化劑項目發(fā)展計劃
- 電子商務(wù)物流信息的存儲效率提升
- 員工辦公自動化系統(tǒng)使用指南
- 幼兒園教育故事小熊的圣誕節(jié)
- 2025年DVD播放設(shè)備合作協(xié)議書
- Sulfamonomethoxine-sodium-Standard-生命科學(xué)試劑-MCE
- 工作解決方案方案
- 藝術(shù)品展覽銷售合作合同
- 北京市城市建設(shè)節(jié)約用地標準
- 復(fù)查(復(fù)核)信訪事項流程圖
- 電源線檢驗報告RVV
- the sad young men上課
- 年晉煤集團薪酬管理辦法
- 八字命理漫畫版
- 機動車駕駛員培訓(xùn)學(xué)校管理制度匯編
- JJF1727-2018噪聲表校準規(guī)范(高清版)
- 護士針刺傷論文
- 入場物流信息系統(tǒng)介紹(唯智版)(谷風課堂)
- 自主改善的活動方案
評論
0/150
提交評論