




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告PAGE5數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告姓名:顧云康學(xué)號(hào):E1114300指導(dǎo)老師:王愛平日期:2013.10.8目錄1課程設(shè)計(jì)的目的 32需求分析 33課程設(shè)計(jì)報(bào)告內(nèi)容 33.1概要設(shè)計(jì) 33.2詳細(xì)設(shè)計(jì) 43.3調(diào)試分析 124總結(jié) 135程序清單 146參考文獻(xiàn) 147程序運(yùn)行結(jié)果 14附錄 15 clock_tbegin3,end3;doublecost3;begin3=clock(); insertSort(number3,MAX); end3=clock(); cost3=(double)(end3-begin3)/CLOCKS_PER_SEC; //梳排序并計(jì)算時(shí)間 clock_tbegin4,end4;doublecost4;begin4=clock(); combsort(number4,MAX); end4=clock(); cost4=(double)(end4-begin4)/CLOCKS_PER_SEC;for(intj=0;j<MAX;j++) { printf("%d",number1[j]); }printf("\n");printf("排序完成!\n");printf("快速排序耗時(shí):%lfseconds\n",cost1);printf("冒泡排序耗時(shí):%lfseconds\n",cost2);printf("插入排序耗時(shí):%lfseconds\n",cost3);printf("梳排序耗時(shí):%lfseconds\n",cost4); return0;}插入排序函數(shù):voidinsertSort(inta[],intlen){ inti,j,temp; for(i=1;i<len;i++) { temp=a[i]; for(j=i-1;j>=0;j--) { if(a[j]>temp) { a[j+1]=a[j]; }else { break; } } a[j+1]=temp; }}冒泡排序函數(shù):voidBubble(inta[],intlen){ intlength=len;inti=0;intj=0;for(;i<len;i++) { for(;j<length;j++) { if(a[j]>a[j+1]) { inttemp=a[j];a[j]=a[j+1];a[j+1]=temp; } }length--;j=0; }}快速排序函數(shù):intpartions(intl[],intlow,inthigh){ intprvotkey=l[low];l[0]=l[low];while(low<high) { while(low<high&&l[high]>=prvotkey) --high;l[low]=l[high];while(low<high&&l[low]<=prvotkey) ++low;l[high]=l[low]; }l[low]=l[0];returnlow;}voidqsort(intl[],intlow,inthigh){ intprvotloc;if(low<high) { prvotloc=partions(l,low,high);//將第一次排序的結(jié)果作為樞軸qsort(l,low,prvotloc-1);//遞歸調(diào)用排序由low到prvotloc-1qsort(l,prvotloc+1,high);//遞歸調(diào)用排序由prvotloc+1到high }}voidquicksort(intl[],intn){ qsort(l,1,n);//第一個(gè)作為樞軸,從第一個(gè)排到第n個(gè)}梳排序函數(shù):voidcombsort(inta[],intn){ floatshrink_factor=1.3;intgap=n,swapped=1,swap,i;while((gap>1)||swapped) { if(gap>1)gap=gap/shrink_factor;swapped=0;i=0;while((gap+i)<n) { if(a[i]-a[i+gap]>0) { swap=a[i];a[i]=a[i+gap];a[i+gap]=swap;swapped=1; }++i; } }}3.3調(diào)試分析(1)使用隨機(jī)數(shù)產(chǎn)生函數(shù),產(chǎn)生40000個(gè)隨機(jī)數(shù),再使用四種算法進(jìn)行排序,并統(tǒng)計(jì)各種算法統(tǒng)計(jì)時(shí)間。運(yùn)行截圖如下:(3)由多次試驗(yàn)結(jié)果可得,梳排序和快速排序的排序速度相對(duì)較快。4總結(jié)通過這次課程設(shè)計(jì)我認(rèn)識(shí)到了排序功能在解決實(shí)際問題中的作用,使我對(duì)數(shù)據(jù)結(jié)構(gòu)的學(xué)習(xí)有了更進(jìn)一步的理解。在完成本次課程設(shè)計(jì)中,我發(fā)現(xiàn)很多理論性知識(shí)在實(shí)際使用時(shí)與單純的理論還是有所差別的,今后我會(huì)更加注重培養(yǎng)自己的實(shí)踐動(dòng)手能力。5程序清單見附錄6參考文獻(xiàn)[1]嚴(yán)蔚敏,吳偉民編著.數(shù)據(jù)結(jié)構(gòu)(C語言版)--北京:清華大學(xué)出版社,2007.[2]嚴(yán)蔚敏,吳偉民米寧編著.數(shù)據(jù)結(jié)構(gòu)題集(C語言版)--北京:清華大學(xué)出版社,2007.[3]/wiki/%E6%A2%B3%E6%8E%92%E5%BA%8F7程序運(yùn)行結(jié)果附錄程序清單:#include"stdafx.h"#include<stdio.h>#include<stdlib.h>#include<time.h>/*用到了time函數(shù),所以要有這個(gè)頭文件*/#defineMAX40000//插入排序voidinsertSort(inta[],intlen){ inti,j,temp; for(i=1;i<len;i++) { temp=a[i]; for(j=i-1;j>=0;j--) { if(a[j]>temp) { a[j+1]=a[j]; }else { break; } } a[j+1]=temp; }}//冒泡排序voidBubble(inta[],intlen){ intlength=len;inti=0;intj=0;for(;i<len;i++) { for(;j<length;j++) { if(a[j]>a[j+1]) { inttemp=a[j];a[j]=a[j+1];a[j+1]=temp; } }length--;j=0; }}//快速排序intpartions(intl[],intlow,inthigh){ intprvotkey=l[low];l[0]=l[low];while(low<high) { while(low<high&&l[high]>=prvotkey) --high;l[low]=l[high];while(low<high&&l[low]<=prvotkey) ++low;l[high]=l[low]; }l[low]=l[0];returnlow;}voidqsort(intl[],intlow,inthigh){ intprvotloc;if(low<high) { prvotloc=partions(l,low,high);//將第一次排序的結(jié)果作為樞軸qsort(l,low,prvotloc-1);//遞歸調(diào)用排序由low到prvotloc-1qsort(l,prvotloc+1,high);//遞歸調(diào)用排序由prvotloc+1到high }}voidquicksort(intl[],intn){ qsort(l,1,n);//第一個(gè)作為樞軸,從第一個(gè)排到第n個(gè)}//梳排序voidcombsort(inta[],intn){ floatshrink_factor=1.3;intgap=n,swapped=1,swap,i;while((gap>1)||swapped) { if(gap>1)gap=gap/shrink_factor;swapped=0;i=0;while((gap+i)<n) { if(a[i]-a[i+gap]>0) { swap=a[i];a[i]=a[i+gap];a[i+gap]=swap;swapped=1; }++i; } }}intmain(){ intnumber[MAX]={0}; intnumber1[MAX]={0}; intnumber2[MAX]={0}; intnumber3[MAX]={0}; intnumber4[MAX]={0};inti;srand((unsigned)time(NULL));/*播種子*/for(i=0;i<MAX;i++) { number[i]=rand()%20000;/*產(chǎn)生101以內(nèi)的隨機(jī)整數(shù)*/number1[i]=number2[i]=number3[i]=number4[i]=number[i];while(number[i]==0) { number[i]=rand()%20000; number1[i]=number2[i]=number3[i]=number4[i]=number[i]; } }//快速排序并計(jì)算時(shí)間 clock_tbegin1,end1;doublecost1;begin1=clock(); quicksort(number1,MAX); end1=clock(); cost1=(double)(end1-begin1)/CLOCKS_PER_SEC;//冒泡排序并計(jì)算時(shí)間 clock_tbegin2,end2;doublecost2;begin2=clock(); Bubble(number2,MAX); end2=clock(); cost2=(double)(end2-begin2)/CLOCKS_PER_SEC; //插入排序并計(jì)算時(shí)間 clock_tbegin3,end3;doublecost3;begin3=clock(); insertSort(number3,MAX); end3=clock(); cost3=(double)(end3-begin3)/CLOCKS_PER_SEC; //梳排序并計(jì)算時(shí)間 clock_tbegin4,end4;doublecost4;begin4=clock(); combsort(number4,MAX); end4=clock(); cost4=(double)(end4-begin4)/CLOCKS_P
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 鄭州城市職業(yè)學(xué)院《影視攝像基礎(chǔ)》2023-2024學(xué)年第二學(xué)期期末試卷
- 漯河食品職業(yè)學(xué)院《會(huì)展項(xiàng)目綜合運(yùn)營(yíng)二》2023-2024學(xué)年第二學(xué)期期末試卷
- 武昌工學(xué)院《測(cè)試自動(dòng)化》2023-2024學(xué)年第二學(xué)期期末試卷
- 沈陽理工大學(xué)《酒店財(cái)務(wù)管理實(shí)驗(yàn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 中國(guó)地質(zhì)大學(xué)(北京)《電力電子變流技術(shù)》2023-2024學(xué)年第二學(xué)期期末試卷
- 2025年氣體檢測(cè)監(jiān)控系統(tǒng)合作協(xié)議書
- 浙江建設(shè)職業(yè)技術(shù)學(xué)院《畫法幾何及陰影透視》2023-2024學(xué)年第二學(xué)期期末試卷
- 寧泌泰膠囊項(xiàng)目效益評(píng)估報(bào)告
- 河南2025年河南鄭州大學(xué)第一附屬醫(yī)院招聘819人筆試歷年參考題庫(kù)附帶答案詳解
- 大連軟件職業(yè)學(xué)院《食品營(yíng)養(yǎng)》2023-2024學(xué)年第二學(xué)期期末試卷
- 高危妊娠及五色管理課件
- 《 大學(xué)生軍事理論教程》全套教學(xué)課件
- 品質(zhì)提升計(jì)劃改善報(bào)告課件
- 景區(qū)明年?duì)I銷工作計(jì)劃
- 中藥材倉(cāng)儲(chǔ)標(biāo)準(zhǔn)化與信息化建設(shè)
- 2型糖尿病性增殖性出血性視網(wǎng)膜病的護(hù)理查房
- 人工智能基礎(chǔ)與應(yīng)用-課程標(biāo)準(zhǔn)
- 業(yè)主授權(quán)租戶安裝充電樁委托書
- 排水管道施工組織設(shè)計(jì)排水管道施工組織設(shè)計(jì)排水施工排水管道施工施工設(shè)計(jì)
- 倉(cāng)庫(kù)管理人員安全培訓(xùn)考試題含答案
- 2024年度核醫(yī)學(xué)科危重癥患者應(yīng)急預(yù)案流程圖
評(píng)論
0/150
提交評(píng)論