




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、1、 程序流程說(shuō)明2、 1)創(chuàng)建一個(gè)單鏈表,其數(shù)據(jù)元素為整數(shù),從鍵盤輸入,輸入0結(jié)束(注意0不放到鏈表內(nèi));3、 2)從鍵盤任意輸入一個(gè)整數(shù),在單鏈表中查詢?cè)摂?shù),如果單鏈表中已經(jīng)存在這個(gè)數(shù),就調(diào)用刪除函數(shù),刪除該元素所在結(jié)點(diǎn),并將單鏈表在刪除前后的數(shù)據(jù)元素依次輸出到屏幕上;4、 如果單鏈表中不存在這個(gè)數(shù),就調(diào)用插入函數(shù),將這個(gè)數(shù)插入到單鏈表尾,并將單鏈表在插入前后的數(shù)據(jù)元素依次輸出到屏幕上。 5、 3)教材第一章習(xí)題第9題(用鏈表實(shí)現(xiàn))ex2_3擴(kuò)展題6、 1)刪除單鏈表中全部的負(fù)數(shù)7、 2)創(chuàng)建一個(gè)雙向鏈表,按照冒泡排序的思路對(duì)這個(gè)雙向鏈表進(jìn)行排序,打印排序結(jié)果。注意,本算法在交換元素時(shí)是將
2、鏈點(diǎn)整個(gè)交換而不是將鏈點(diǎn)中的元素值交換。8、 9、10、11、2_21)創(chuàng)建一個(gè)單鏈表,其數(shù)據(jù)元素為整數(shù),從鍵盤輸入,輸入0結(jié)束(注意0不放到鏈表內(nèi));(if x!=0,scanf) 2)從鍵盤任意輸入一個(gè)整數(shù),在單鏈表中查詢?cè)摂?shù),如果單鏈表中已經(jīng)存在這個(gè)數(shù),就調(diào)用刪除函數(shù),刪除該元素所在結(jié)點(diǎn),并將單鏈表在刪除前后的數(shù)據(jù)元素依次輸出到屏幕上;(search 返回重復(fù)的位置,然后刪除(同實(shí)驗(yàn)一) 如果單鏈表中不存在這個(gè)數(shù),就調(diào)用插入函數(shù),將這個(gè)數(shù)插入到單鏈表尾,并將單鏈表在插入前后的數(shù)據(jù)元素依次輸出到屏幕上。(同實(shí)驗(yàn)一,直接加在鏈表末尾)3)判斷插入元素與表內(nèi)元素的大小,如temp->da
3、ta<x<temp->link->data,則插入temp后2_31)刪除單鏈表中全部的負(fù)數(shù)(逐個(gè)判斷是不是負(fù)數(shù),并且返回負(fù)數(shù)所在位置,刪除過(guò)春哥同實(shí)驗(yàn)一)2)創(chuàng)建一個(gè)雙向鏈表,按照冒泡排序的思路對(duì)這個(gè)雙向鏈表進(jìn)行排序,打印排序結(jié)果。注意,本算法在交換元素時(shí)是將鏈點(diǎn)整個(gè)交換而不是將鏈點(diǎn)中的元素值交換。(從一開始逐個(gè)比較,將比第一位大的與第一位交換位置,一直比較到最后一位然后開始對(duì)于第二位重復(fù)比較)二、程序代碼2_2#include<stdio.h>#include<malloc.h>#include<stdlib.h>typedef
4、struct Nodeint data;struct Node *link;node;typedef struct Listnode *head;node *tail;int length;list;void creat_list(list *table)int x,i;node *temp;table->head=NULL;table->tail=NULL;table->length=0; x=1;scanf("%d",&x);for(i=0;x!=0;i+)fflush(stdin);printf("n");temp=(no
5、de*)malloc(sizeof(node);temp->data=x;temp->link=NULL;temp->link=table->head;table->head=temp;table->length+;scanf("%d",&x);node * create_node(int new_node)node * temp;temp = (node*)malloc(sizeof(node);temp->data = new_node;temp->link = NULL;return temp;void get(
6、list *table,int n)int i,loc=table->length+1;node *temp;node *newnode;temp=table->head;table->length+;newnode=create_node(n);for(i=2;i<loc;i+)temp=temp->link;newnode->link = temp->link; temp->link = newnode;void show_list(list *table)int x,i;node *temp;printf("鏈表為:n"
7、);temp=table->head;for(i=1;i <= table->length;i+)x=temp->data;printf("%d ",x);temp=temp->link;void delete_node(list *table,int n)int i;node *temp,*t;temp=table->head;if(n=1)temp=temp->link;table->head=temp;if(n>2&&n<table->length)temp=table->head
8、;for(i=2;i<n;i+)temp=temp->link;t=temp->link;temp->link=t->link; if(n=table->length)for(i=2;i<n;i+)temp=temp->link; temp->link=NULL;if(n=2)temp=table->head;t=temp->link;temp->link=t->link;table->length-;void search(list *table,int x,int a2)int i=0,j=0;node *
9、temp;temp=table->head;for(i=1;i<=table->length;i+)if(x=temp->data)a1=i;j+;temp=temp->link;if(j=0)a0=0;a1=0;elsea0=1;void main()list table;int m,a2;creat_list(&table);show_list(&table);printf("n輸入一個(gè)整數(shù)n");scanf("%d",&m);search(&table,m,a);if(a0=1)dele
10、te_node(&table,a1);show_list(&table);elseget(&table,m);show_list(&table);2_2(3)#include<stdio.h>#include<malloc.h>#include<stdlib.h>typedef struct Nodeint data;struct Node *link;node;typedef struct Listnode *head;node *tail;int length;list;void creat_list(list *tabl
11、e)int x,i;node *temp;table->head=NULL;table->tail=NULL;table->length=0; x=1;scanf("%d",&x);for(i=0;x!=0;i+)fflush(stdin);printf("n");temp=(node*)malloc(sizeof(node);temp->data=x;temp->link=NULL;temp->link=table->head;table->head=temp;table->length+;
12、scanf("%d",&x);node * create_node(int new_node)node * temp;temp = (node*)malloc(sizeof(node);temp->data = new_node;temp->link = NULL;return temp;void get(list *table,int n)int i,m=0;node *temp;node *newnode;temp=table->head;table->length+;newnode=create_node(n);if(n<temp
13、->data)newnode->link=temp;temp=newnode;elsefor(i=1;m=0;i+)if(i<=table->length&&temp->data<n&&n<=temp->link->data)newnode->link = temp->link; temp->link = newnode;m=1;else if(i=table->length)temp->link=newnode;newnode->link=NULL;m=1;temp=te
14、mp->link;table->length+;void show_list(list *table)int x,i;node *temp;printf("鏈表為:n");temp=table->head;for(i=1;i <= table->length;i+)x=temp->data;printf("%d ",x);temp=temp->link;void main()list table;int m,a2;creat_list(&table);show_list(&table);print
15、f("n輸入一個(gè)整數(shù)n");scanf("%d",&m);get(&table,m);show_list(&table);2_3(1)#include<stdio.h>#include<malloc.h>#include<stdlib.h>typedef struct Nodeint data;struct Node *link;node;typedef struct Listnode *head;node *tail;int length;list;void creat_list(list *
16、table)int x,i;node *temp;table->head=NULL;table->tail=NULL;table->length=0; x=1;scanf("%d",&x);for(i=0;x!=0;i+)fflush(stdin);printf("n");temp=(node*)malloc(sizeof(node);temp->data=x;temp->link=NULL;temp->link=table->head;table->head=temp;table->leng
17、th+;scanf("%d",&x);node * create_node(int new_node)node * temp;temp = (node*)malloc(sizeof(node);temp->data = new_node;temp->link = NULL;return temp;void get(list *table,int n)int i,loc=table->length+1;node *temp;node *newnode;temp=table->head;table->length+;newnode=crea
18、te_node(n);for(i=2;i<loc;i+)temp=temp->link;newnode->link = temp->link; temp->link = newnode;void show_list(list *table)int x,i;node *temp;printf("n鏈表為:n");temp=table->head;for(i=1;i <= table->length;i+)x=temp->data;printf("%d ",x);temp=temp->link;vo
19、id delete_node(list *table,int n)int i;node *temp,*t;temp=table->head;if(n=1)temp=temp->link;table->head=temp;if(n>2&&n<table->length)temp=table->head;for(i=2;i<n;i+)temp=temp->link;t=temp->link;temp->link=t->link; if(n=table->length)for(i=2;i<n;i+)t
20、emp=temp->link; temp->link=NULL;if(n=2)temp=table->head;t=temp->link;temp->link=t->link;table->length-;void search(list *table,int a2)int i=0,j=0;node *temp;temp=table->head;for(i=1;i<=table->length;i+)if(temp->data<0)a1=i;j=1;break;temp=temp->link;if(j=0)a0=0;
21、a1=0;elsea0=1;void paixu(list *table)int i,j,m,u;node *temp,*t,*p;for(i=1;i<=table->length;i+)temp=table->head;for(u=1;u<i;u+)temp=temp->link;t=temp;for(j=i;j<=table->length;j+)temp=t;for(m=i;m<=j;m+)temp=temp->link;if(t->data<(temp->data)p=temp->link;temp->
22、link=t->link;t->link=p;void main()list table;int m,a2;creat_list(&table);show_list(&table);search(&table,a);for(m=1;a0=1;m+)search(&table,a);if(a0=1)delete_node(&table,a1);show_list(&table);2_3(2)#include<stdio.h>#include<malloc.h>#include<stdlib.h>typ
23、edef struct Nodeint data;struct Node *link,*last;node;typedef struct Listnode *head;node *tail;int length;list;void creat_list(list *table)int x,i;node *temp,*t,*p;table->head=NULL;table->tail=NULL;table->length=0; x=1;scanf("%d",&x);for(i=0;x!=0;i+)fflush(stdin);printf("
24、n");temp=(node*)malloc(sizeof(node);temp->data=x;temp->link=NULL;temp->link=table->head;table->head=temp;table->length+;scanf("%d",&x);t=(node*)malloc(sizeof(node);t=table->head;t->last=NULL;for(i=2;i<=table->length;i+)p=t;t=t->link;t->last=p;vo
25、id show_list(list *table)int x,i;node *temp;printf("鏈表為:n");temp=table->head;for(i=1;i <= table->length;i+)x=temp->data;printf("%d ",x);temp=temp->link;void paixu(list *table)int i,j,m;node *temp,*t,*p,*q;temp=table->head;t=temp;for(i=2;i<=table->length;i+
26、)t=t->link;if(t->data>temp->data)p=t->link;t->link=temp->link;temp->link=p;t->last->link=temp;table->head=t;t->last=NULL;temp->last=t->last;p=t;t=temp;temp=t;/*/temp=table->head;for(i=2;i<=table->length;i+)temp=temp->link;t=temp;for(j=i+1;j<=table->length;j+)t=t->link;if(t->data>temp->data)p=t->link;t->link=temp->link;temp->link=p;t->last->link=temp;tem
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 江蘇蘇州2024~2025學(xué)年高二下冊(cè)6月期末考試數(shù)學(xué)試題含解析
- 地方特色教育課程與公民素養(yǎng)教育融合考核試卷
- 2025年中國(guó)PE信封粘膠袋數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2025年中國(guó)LCD彩色監(jiān)視器數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2025年中國(guó)DWDM密集波分復(fù)用測(cè)試儀數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2025年中國(guó)6毫米CNG高壓鋼管PVC數(shù)據(jù)監(jiān)測(cè)研究報(bào)告
- 2025年中國(guó)16路混合器數(shù)據(jù)監(jiān)測(cè)報(bào)告
- 2025至2030年中國(guó)高真空擴(kuò)散泵油市場(chǎng)分析及競(jìng)爭(zhēng)策略研究報(bào)告
- 2025至2030年中國(guó)防毒面具箱市場(chǎng)分析及競(jìng)爭(zhēng)策略研究報(bào)告
- 2025至2030年中國(guó)針型皮帶扣市場(chǎng)分析及競(jìng)爭(zhēng)策略研究報(bào)告
- 2024-2025學(xué)年成都市教科院附屬學(xué)校重點(diǎn)中學(xué)初三下學(xué)期教學(xué)質(zhì)量檢測(cè)試題英語(yǔ)試題含答案
- 豬肉聯(lián)營(yíng)合作協(xié)議范本(2024版)
- 企業(yè)內(nèi)刊策劃
- 智能化設(shè)備技術(shù)規(guī)格書范本
- 電子商務(wù)數(shù)據(jù)分析題庫(kù)與參考答案
- 期末考試-公共財(cái)政概論-章節(jié)習(xí)題
- 幼兒園體能大循環(huán)培訓(xùn)
- 團(tuán)體心理咨詢的主要理論專家講座
- 骨盆骨折中醫(yī)護(hù)理常規(guī)
- mil-std-1916抽樣標(biāo)準(zhǔn)(中文版)
- 大學(xué)學(xué)院“十四五”師資隊(duì)伍建設(shè)規(guī)劃(2021-2025)
評(píng)論
0/150
提交評(píng)論