




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、實驗二 鏈表的實現(xiàn)和應(yīng)用一、 實驗?zāi)康恼莆站€性表的鏈式存儲結(jié)構(gòu)設(shè)計與基本操作的實現(xiàn)二、 實驗內(nèi)容與要求 定義線性表的鏈式存儲表示; 基于所設(shè)計的存儲結(jié)構(gòu)實現(xiàn)線性表的基本操作; 編寫一個主程序?qū)λ鶎崿F(xiàn)的線性表進行測試; 線性表的應(yīng)用:設(shè)線性表L1和L2分別代表集合A和B,試設(shè)計算法求A和B的并集C,并用線性表L3代表集合C;設(shè)線性表L1和L2中的數(shù)據(jù)元素為整數(shù),且均已按值非遞減有序排列,試設(shè)計算法對L1和L2進行合并,用線性表L3保存合并結(jié)果,要求L3中的數(shù)據(jù)元素也按值非遞減有序排列。三、 數(shù)據(jù)結(jié)構(gòu)設(shè)計 在主函數(shù)中實現(xiàn)函數(shù)的調(diào)用,從而實現(xiàn)線性表的插入、刪除、創(chuàng)建、顯示等。四、 測試結(jié)果 通過輸入
2、不同的數(shù)字(16)實現(xiàn)不同的操作,在兩個線性表結(jié)合時,線性表二在源程序中已給出的,通過操作可以得到非單調(diào)遞減的有序數(shù)列五、 心得體會 在寫程序的過程中要注意分析,參照其他標準程序,多上機運行一點點的改正錯誤,這樣才會有所提高。MAIN.C 方麗平 信計1203班 1130112321 最后修改時間2014/3/31#include<stdio.h>#include<stdlib.h>#define maxsize 1024typedef int datatype;typedef struct nodedatatype data;struct node * next;li
3、nkList;int main()linkList * CREATE();int INSERT(linkList *head, int value, int position);int DELETE(linkList *head, int position);int DISPLAY(linkList *head);linkList * COMBINE(linkList *head1, linkList *head2);linkList * head1;linkList * head2;linkList * head3;linkList * head;linkList * p1,* p2,* s
4、1,* s2,* r1,* r2;int position, value, i;head1 = malloc(sizeof(linkList);r1 = head1;head2 = malloc(sizeof(linkList);r2 = head2;for(i = 0; i< 20; i+)s1 = malloc(sizeof(linkList);s1 ->data = i;r1 ->next = s1;r1 = s1;s2 = malloc(sizeof(linkList);s2 ->data = i + 2;r2 ->next = s2;r2 = s2;r2
5、 -> next = NULL;r1 -> next = NULL;while(1) printf("the program n"); printf("can realize to create,insert,delete,display,etcn"); printf("1:create the ranked listn"); printf("2:insert a datan"); printf("3:delete a datan"); printf("4:display
6、all the datan"); printf("5:Combine two link lists of operationn"); printf("6:return,end of the programn"); printf("selection of operationn"); scanf("%d",&i); while ( i < 1 | i > 6 ) printf("please input againn"); scanf("%d",&
7、amp;i); switch(i) case 1: head = CREATE(); break; case 2: /*INSERT(p);*/ printf("Please input insert placen"); scanf("%d",&position);printf("Please input insert valuen"); scanf("%d",&value);INSERT(head, value, position); break; case 3: printf("Ple
8、ase input delete positionn"); scanf("%d",&value);DELETE(head, position); break; case 4: DISPLAY(head); break;case 5:printf("The list 1:n");DISPLAY(head1);printf("The list 2:n");DISPLAY(head2);printf("The combine list:n");head3 = COMBINE(head1, head2);
9、DISPLAY(head3);break; case 6: exit(0); break; linkList * CREATE() int value; linkList * head,* s,* r; head = malloc(sizeof(linkList); r = head; printf("input the data of the number,input 55 over!"); scanf("%d",&value); do s = malloc(sizeof(linkList); s ->data = value; r -&
10、gt;next = s; r = s; printf("input the data of the number"); scanf("%d",&value); while(value != 55); r -> next = NULL; return head;int INSERT(linkList *head,int value, int position)int j = 1;linkList *p,*s,*n;s = malloc(sizeof(linkList);s ->data = value;p = head;printf(&
11、quot;Note:if the position is greater than the length of the table will be put in the final");while(j < position)if( (p -> next) != NULL )p = p -> next;j +;n = p -> next;s -> next =n;p -> next = s;return 0; int DELETE(linkList *head, int position)int j;linkList *p;linkList *s;p
12、 = head;printf("Note:if the position is greater than the length of the table will be delete nothing!");for(j = 1;j < position; j +)if( (p -> next) != NULL )p = p -> next;elsereturn 0;s = p -> next;if(s -> next) != NULL)(*p).next = (*s).next;s = NULL;return 0;int DISPLAY(link
13、List *head)linkList *p;int i;i = 0;p = head -> next; while(p != NULL) printf("%5d",(*p).data); p = p -> next; i +; if(i % 5 = 0) printf("n"); return 0;linkList * COMBINE(linkList *head1, linkList *head2)linkList *head,*r;linkList *p1, *p2,*s;head = malloc(sizeof(linkList);r
14、 = head;p1 = malloc(sizeof(linkList);p2 = malloc(sizeof(linkList);p1 = head1 -> next;p2 = head2 -> next;dos = malloc(sizeof(linkList);if( (p1 != NULL) && (p2 != NULL) )if(p1 -> data < p2 -> data )s -> data = p1 -> data;p1 = p1 ->next;elses -> data = p2 -> data;p2 = p2 ->next;else if( (p1 != NULL) && (
溫馨提示
- 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)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權(quán)】 ISO/TR 21734-3:2024 EN Intelligent transport systems - Performance testing for connectivity and safety functions of automated driving buses in public transport - Part 3: Ser
- 【正版授權(quán)】 ISO 20553:2025 EN Radiation protection - Monitoring of workers occupationally exposed to a risk of internal contamination with radioactive material
- 2025年度拆遷安置房預(yù)售合同范本(2025版)
- 2025年生物科技產(chǎn)品采購合同范本模板
- 2025年度餐廳窗口承包及廣告投放合同
- 2025年度二手商鋪貸款買賣雙方合作協(xié)議
- 2025年度海洋工程擔保型買賣合同
- 2025年低噪聲對旋式局部通風(fēng)機項目建議書
- 保安工作在社區(qū)安全提升中的實例計劃
- 促進社區(qū)志愿服務(wù)團隊建設(shè)的方案計劃
- 節(jié)事活動策劃與組織管理 節(jié)事活動概論
- 電梯安裝質(zhì)量手冊、程序文件、作業(yè)指導(dǎo)書及記錄表符合特種設(shè)備許可規(guī)范TSG07-2019
- 肋骨骨折病人的業(yè)務(wù)學(xué)習(xí)
- 生產(chǎn)建設(shè)項目水土保持補償費免征申請表
- 全過程工程咨詢服務(wù)大綱
- 日本酒類消費行業(yè)市場分析報告
- GB/T 4151-1996硝酸鈰
- GB/T 31586.2-2015防護涂料體系對鋼結(jié)構(gòu)的防腐蝕保護涂層附著力/內(nèi)聚力(破壞強度)的評定和驗收準則第2部分:劃格試驗和劃叉試驗
- GB/T 29594-2013可再分散性乳膠粉
- 危房鑒定報告
- 西子奧的斯電梯ACD2調(diào)試說明書
評論
0/150
提交評論