




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、電子科技大學(xué) 通信與信息工程 學(xué)院標(biāo) 準(zhǔn) 實(shí) 驗(yàn) 報(bào) 告(實(shí)驗(yàn))課程名稱 軟件技術(shù)基礎(chǔ)實(shí)驗(yàn) 電子科技大學(xué)教務(wù)處制表電 子 科 技 大 學(xué)實(shí) 驗(yàn) 報(bào) 告一、實(shí)驗(yàn)室名稱: 校公共機(jī)房 二、實(shí)驗(yàn)項(xiàng)目名稱:鏈表程序設(shè)計(jì)三、實(shí)驗(yàn)學(xué)時(shí):4學(xué)時(shí)四、實(shí)驗(yàn)原理:使用VS2010等C語(yǔ)言集成開發(fā)環(huán)境(IDE),在微型計(jì)算機(jī)上對(duì)程序進(jìn)行編輯、編譯、連接與運(yùn)行。通過(guò)上機(jī)練習(xí)掌握在鏈表的建立、插入刪除等方法和過(guò)程。五、實(shí)驗(yàn)?zāi)康模?. 熟練鏈表的概念和基本操作方法。2. 掌握課程平臺(tái)使用方法。六、實(shí)驗(yàn)內(nèi)容:上機(jī)完成鏈表的一系列操作,并用鏈表完成課后習(xí)題9,編程實(shí)驗(yàn),調(diào)試運(yùn)行程序并完成報(bào)告。七、實(shí)驗(yàn)器材(設(shè)備、元器件):硬
2、件要求:普通pc機(jī),1G內(nèi)存,100G硬盤空間即可。 軟件要求:Windows 7,包括C編譯器的IDE。八、實(shí)驗(yàn)步驟、實(shí)驗(yàn)編程與運(yùn)行結(jié)果:1. 程序文件名為*.cpp,源程序清單如下:/*基礎(chǔ)實(shí)驗(yàn)1,鏈表的建立,插入,刪除*/#include<stdio.h> #include<stdlib.h>struct listint info;struct list *next;struct list *Create(int *numnode)/創(chuàng)建一個(gè)鏈表struct list *head,*tail,*cnew;head=NULL;int num;printf("
3、;輸入數(shù)據(jù)(以零結(jié)束):");while(1) scanf("%d",&num); if(num=0)/輸入為零表示輸入結(jié)束 break; cnew=(struct list*)malloc(sizeof(struct list); cnew->info=num; cnew->next=NULL; if(head=NULL)/若為空則將頭節(jié)點(diǎn)指向新節(jié)點(diǎn) head=cnew; else tail->next=cnew;/將當(dāng)前節(jié)點(diǎn)的next指向新的節(jié)點(diǎn) tail=cnew; (*numnode)+;return head;void inse
4、rt(struct list *h,int i,int x) struct list *p,*t; int j; p=h; j=0; while(p!=NULL&&j<i-1) p=p->next; j+; if(j!=i-1) printf("overflow!"); else t=(struct list*)malloc(sizeof(struct list); t->info=x; t->next=p->next; p->next=t; struct list *insert_head(struct list *h,
5、int x) struct list *p,*t; p=h; t=(struct list*)malloc(sizeof(struct list); t->info=x; t->next=h; return t;struct list *Delete_head(struct list *h) struct list *p; p = h;h = h->next;free(p); return h;void Delete(struct list *h,int i) struct list *p,*s; int j; p=h; j=0; while(p->next!=NULL
6、&&j<i-1) p=p->next; j=j+1; if(j!=i-1) printf("overflow!");else s=p->next; p->next=p->next->next; free(s);void display(struct list *head)struct list *p;if(head=NULL)printf("鏈表為空,沒有數(shù)據(jù)n");return;printf("n鏈表的數(shù)據(jù)元素:n");for(p=head;p!=NULL;p=p->next
7、) printf("%d ",p->info);printf("n");int main()struct list *head1;int numnode1,point1,point2;int ne,p,q;numnode1=0;head1=NULL;/初始化將節(jié)點(diǎn)個(gè)數(shù)初始化為零head1=Create(&numnode1);display(head1);printf("n鏈表head1的節(jié)點(diǎn)個(gè)數(shù)為:%dn",numnode1);printf("input new element:");scanf(&q
8、uot;n%d",&ne);printf("nthe point of new element:");scanf("%d",&p);if(p=1) head1=insert_head(head1,ne);else insert(head1,(p-1),ne);display(head1);printf("ndelete point:");scanf("%d",&q);if(q=1) head1=Delete_head(head1);else Delete(head1,(q-1);d
9、isplay(head1);/*實(shí)驗(yàn)2,鏈表中元素的刪除,刪除失敗則插入*/#include<stdio.h>#include<stdlib.h>struct listint info;/節(jié)點(diǎn)信息struct list *next;struct list *Create(int *numnode)/創(chuàng)建一個(gè)鏈表struct list *head,*tail,*cnew;head=NULL;int num;printf("輸入數(shù)據(jù)(以零結(jié)束):");while(1) scanf("%d",&num); if(num=0)/輸
10、入為零表示輸入結(jié)束 break; cnew=(struct list*)malloc(sizeof(struct list); cnew->info=num; cnew->next=NULL; if(head=NULL)/若為空則將頭節(jié)點(diǎn)指向新節(jié)點(diǎn) head=cnew; else tail->next=cnew;/將當(dāng)前節(jié)點(diǎn)的next指向新的節(jié)點(diǎn) tail=cnew; (*numnode)+;return head;int find(struct list *head,int fab) struct list *p; int flag=0,j=0; for(p=head;p!
11、=NULL;p=p->next) j=j+1; if(p->info=fab) return j;flag=1; if(flag=0) return -1;void Delete(struct list *h,int i) struct list *p,*s; int j; p=h; j=0; while(p->next!=NULL&&j<i-1) p=p->next; j=j+1; if(j!=i-1) printf("overflow!"); else s=p->next; p->next=p->next-
12、>next; free(s); void insert(struct list *h,int i,int x) struct list *p,*t; int j; p=h; j=0; while(p!=NULL&&j<i-1) p=p->next; j+; if(j!=i-1) printf("overflow!"); t=(struct list*)malloc(sizeof(struct list); t->info=x; t->next=p->next; p->next=t;void display(struc
13、t list *head)/遍歷鏈表輸出struct list *p;if(head=NULL)printf("鏈表為空,沒有數(shù)據(jù)n");return;printf("n-鏈表的數(shù)據(jù)元素-n");for(p=head;p!=NULL;p=p->next) printf("%d ",p->info);printf("n");int main()struct list *head1;int numnode1,a,q;numnode1=0;head1=NULL;/初始化將節(jié)點(diǎn)個(gè)數(shù)初始化為零head1=Crea
14、te(&numnode1);display(head1);printf("delete:");scanf("%d",&a);q=(find(head1,a)-1);if(q<0) insert(head1,numnode1,a); else Delete(head1,q); display(head1);/*實(shí)驗(yàn)3,課本習(xí)題,自動(dòng)判斷位置并插入,鏈表實(shí)現(xiàn)*/#include<stdio.h>#include<stdlib.h>struct listint info;struct list *next;stru
15、ct list *Create(int *numnode)/創(chuàng)建一個(gè)鏈表struct list *head,*tail,*cnew;head=NULL;int num;printf("輸入數(shù)據(jù)(以零結(jié)束):");while(1) scanf("%d",&num); if(num=0)/輸入為零表示輸入結(jié)束 break; cnew=(struct list*)malloc(sizeof(struct list); cnew->info=num; cnew->next=NULL; if(head=NULL)/若為空則將頭節(jié)點(diǎn)指向新節(jié)點(diǎn) h
16、ead=cnew; else tail->next=cnew;/將當(dāng)前節(jié)點(diǎn)的next指向新的節(jié)點(diǎn) tail=cnew; (*numnode)+;return head;void insert(struct list *h,int i,int x) struct list *p,*t; int j; p=h; j=0; while(p!=NULL&&j<i-1) p=p->next; j+; if(j!=i-1) printf("overflow!"); else t=(struct list*)malloc(sizeof(struct li
17、st); t->info=x; t->next=p->next; p->next=t; struct list *insert_head(struct list *h,int x) struct list *p,*t; p=h; t=(struct list*)malloc(sizeof(struct list); t->info=x; t->next=h; return t;int find_position(struct list *head,int n_ew) struct list *p; int flag,j=0; for(p=head;p!=NU
18、LL;p=p->next) j=j+1; if(n_ew<=p->info) return j;flag=1;break; void display(struct list *head)struct list *p;if(head=NULL)printf("鏈表為空,沒有數(shù)據(jù)n");return;printf("n鏈表的數(shù)據(jù)元素:n");for(p=head;p!=NULL;p=p->next) printf("%d ",p->info);printf("n");int main()struct list *head1;int numnode1,point1,point2;int ne,p;numnode1=0;head
溫馨提示
- 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ù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 鄉(xiāng)村和城鎮(zhèn)試題及答案
- 物流包裝試題及答案
- 安徽省A10聯(lián)盟2024-2025學(xué)年高二下學(xué)期5月學(xué)情調(diào)研考地理(B)試卷(含答案)
- 2025年黑龍江省哈爾濱市中考模擬試題數(shù)學(xué)試卷(含簡(jiǎn)單答案)
- 2025船舶交易合同范本下載
- 2025屆高考物理大一輪復(fù)習(xí)課件 第十一章 第64課時(shí) 專題強(qiáng)化:復(fù)合場(chǎng)中的擺線問(wèn)題 動(dòng)量定理在磁場(chǎng)中的應(yīng)用
- 2025屆高考物理大一輪復(fù)習(xí)課件 第十一章 第60課時(shí) 專題強(qiáng)化:用“動(dòng)態(tài)圓”思想分析臨界問(wèn)題
- 初中語(yǔ)文 中考專區(qū) 二輪專題 議論文閱讀 課件
- 2024年中考物理復(fù)習(xí)專題 計(jì)算與推導(dǎo)題初中物理 中考專區(qū) 復(fù)習(xí)
- 2025授權(quán)創(chuàng)作合同范本示例
- 智障個(gè)別化教育計(jì)劃案例(3篇)
- 血小板膜蛋白功能研究-洞察分析
- 高級(jí)財(cái)務(wù)會(huì)計(jì)-合并財(cái)務(wù)報(bào)表知到智慧樹章節(jié)測(cè)試課后答案2024年秋山東大學(xué)(威海)
- 部編版四年級(jí)語(yǔ)文下冊(cè)第六單元教學(xué)計(jì)劃(含課標(biāo)分析、教材分析、單元教學(xué)目標(biāo)、教學(xué)策略、學(xué)情分析等)
- 用火用電用氣安全管理制度
- 《腦出血護(hù)理》課件
- 習(xí)慣性違章行為培訓(xùn)課件
- 北京師范大學(xué)珠海分?!秾W(xué)校心理學(xué)》2021-2022學(xué)年第一學(xué)期期末試卷
- (TCSEB 0011-2020)《露天爆破工程技術(shù)設(shè)計(jì)規(guī)范》
- 2025年煤礦井下作業(yè)安全員理論全國(guó)考試題庫(kù)(含答案)
- 《化工新材料生產(chǎn)技術(shù)》課件-知識(shí)點(diǎn)2 聚碳酸酯生產(chǎn)工藝流程
評(píng)論
0/150
提交評(píng)論