![綜合排序數(shù)據(jù)結(jié)構(gòu)課程設(shè)計_第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-6/20/50d58d66-5a03-4bef-b8fb-64647ab0dce3/50d58d66-5a03-4bef-b8fb-64647ab0dce31.gif)
![綜合排序數(shù)據(jù)結(jié)構(gòu)課程設(shè)計_第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-6/20/50d58d66-5a03-4bef-b8fb-64647ab0dce3/50d58d66-5a03-4bef-b8fb-64647ab0dce32.gif)
![綜合排序數(shù)據(jù)結(jié)構(gòu)課程設(shè)計_第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-6/20/50d58d66-5a03-4bef-b8fb-64647ab0dce3/50d58d66-5a03-4bef-b8fb-64647ab0dce33.gif)
![綜合排序數(shù)據(jù)結(jié)構(gòu)課程設(shè)計_第4頁](http://file2.renrendoc.com/fileroot_temp3/2021-6/20/50d58d66-5a03-4bef-b8fb-64647ab0dce3/50d58d66-5a03-4bef-b8fb-64647ab0dce34.gif)
![綜合排序數(shù)據(jù)結(jié)構(gòu)課程設(shè)計_第5頁](http://file2.renrendoc.com/fileroot_temp3/2021-6/20/50d58d66-5a03-4bef-b8fb-64647ab0dce3/50d58d66-5a03-4bef-b8fb-64647ab0dce35.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、題 目:綜合排序-數(shù)據(jù)結(jié)構(gòu)課程設(shè)計 院 系:信息工程學(xué)院專 業(yè):計算機科學(xué)與技術(shù)班 級:姓 名:學(xué) 號:指導(dǎo)老師:時 間:目錄一、問題描述4二、內(nèi)容簡介42.1 基本要求:42.2. 算法思想:42.3. 模塊劃分:42.4. 數(shù)據(jù)結(jié)構(gòu):52.5. 源程序:52.6. 測試情況:14三、小結(jié)17一、 問題描述利用隨機函數(shù)產(chǎn)生n個隨機整數(shù)(20000以上),對這些數(shù)進行多種方法進行排序。要求:1) 至少采用三種方法實現(xiàn)上述問題求解(提示,可采用的方法有插入排序、希爾排序、起泡排序、快速排序、選擇排序、堆排序、歸并排序)。并把排序后的結(jié)果保存在不同的文件中。2) 統(tǒng)計每一種排序方法的性能(以上機運
2、行程序所花費的時間為準(zhǔn)進行對比),找出其中兩種較快的方法。3) 如果采用4種或4種以上的方法者,可適當(dāng)加分。二、 內(nèi)容簡介2.1 基本要求:(1) 設(shè)計一個的菜單將在實現(xiàn)的功能顯示出來,并有選擇提示(2) 分別實現(xiàn)直接插入排序、折半插入排序、希爾排序、冒泡排序、快速排序、簡單排序、堆排序算法;(3) 通過多種測試數(shù)據(jù),對各種排序算法的時間復(fù)雜度和空間復(fù)雜度進行比較2.2. 算法思想:1.處理流程圖開始直接插入排序時間效率比較直接選擇排序顯示菜單冒泡排序快速排序堆排序顯示隨機數(shù)顯示排序后的的數(shù)據(jù)和時間效率輸入序號結(jié)束退出隨機數(shù)顯示各個排序法對同一組數(shù)據(jù)排序所用的時間和其中兩種較快的方法12345
3、670void bublesort(double a)時間數(shù)組的冒泡排序void insertsort(int a,int p)void selectsort(int a,int p)void disp(int a)void creatheap(int a,int i,int n) void heapsort(int a,int n,int p)double tinsertsort(int a,int p)void quicksort(int a,int n, int p)void bubblesort(int a,int p)double tselectsort(int a,int p)do
4、uble tquicksort(int a,int left, int right,int p)double tbubblesort(int a,int p)double theapsort(int a,int n,int p)3.設(shè)計一個高精度時間函數(shù),分別測試各種排序的時間消耗;4.在主函數(shù)中,用開關(guān)語句swtich()case 值1;break;case值n;break;default語句序列:n+1;調(diào)用各種排序算法,各種排序的時間消耗函數(shù),從而在屏幕上輸出供選擇的菜單,各種排序時間和空間復(fù)雜度的比較。2.3. 模塊劃分:1.輸入初始數(shù)據(jù)函數(shù):int makelist(recnode
5、*r) 2.輸出未排序前的數(shù)據(jù)函數(shù):void undealoutlist(recnode *r,int n) 3.處理后的序列函數(shù):void dealoutlist(recnode*r,int n) 4.這種排序的算法:void insertsort(recnode*r,int n)/直接插入排序void biinsertionsort (recnode*r, int n) / 折半插入排序void bublesort(recnode *r,int n) /冒泡排序int partition(recnode*r,int*low,int*high)/一趟快速排序void quicksort(re
6、cnode*r,int start,int end)/快速排序void selesort(recnode*r,int n)/直接選擇排序void shellsort(recnode *r,int n)/希爾排序void sift(recnode*r,int i,int m)void heapsort(recnode*r,int n)/堆排序5.排序時間測試函數(shù):double tinsertsort(int len,recnode *a,int p)2.4. 數(shù)據(jù)結(jié)構(gòu):1.預(yù)定義常量和自定義類型:#define maxsize 100 typedef struct int key; recnod
7、e;2.基本函數(shù)的算法用以下形式表示:函數(shù)類型 函數(shù)名(函數(shù)參數(shù)表)/算法說明 語句序列/函數(shù)名。3.定義 int b,t,i,j; /b為記錄交換的次數(shù),t為記錄排序的趟數(shù),i為排序的數(shù)據(jù),j為暫存數(shù)據(jù)的臨時變量。4. 輸入初始數(shù)據(jù)函數(shù)中定義int k, j,k為輸入數(shù)據(jù)個數(shù),j為輸入的數(shù)據(jù)。5.快速排序中定義static int w=0,int *low,*high。6.在直接選擇排序中定義int z,臨時儲存i的值。7.在希爾排序中定義int dk,記錄前后位置的增量。8.在排序時間消耗測試的函數(shù)和主函數(shù)中定義了int p,為菜單的序號。9.在主函數(shù)中定義int len,為測試數(shù)據(jù)的總長
8、度。2.5. 源程序:插入排序核心代碼void insertsort(int a,int p) int i,j,temp; for(i=1;i0&aj-1temp;j-) aj=aj-1; aj=temp; 選擇排序核心代碼void selectsort(int a,int p) int i,j,k; for(i=0;in-1;i+) k=i; for(j=i+1;jn;j+) if(ajak) k=j; if(k!=i) int temp; temp=ak; ak=ai; ai=temp; 冒泡排序算法核心代碼void bubblesort(int a,int p) int i,j,temp
9、; for (i=0;ii;j-) /*比較,找出本趟最小關(guān)鍵字的記錄*/ if (ajaj-1) temp=aj; /*進行交換,將最小關(guān)鍵字記錄前移*/ aj=aj-1; aj-1=temp; 創(chuàng)建堆核心代碼void creatheap(int a,int i,int n) int j;int t;t=ai;j=2*(i+1)-1;while(j=n)if(jn)&(ajaj+1)j+;if(t=0;i-)creatheap(a,i,n-1);for(i=n-1;i=1;i-)t=a0;a0=ai;ai=t;creatheap(a,0,i-1);快速排序核心代碼void quicksort
10、(int a,int n,int p) int i,j,low,high,temp,top=-1; struct node int low,high; stn; top+; sttop.low=0;sttop.high=n-1; while(top-1) low=sttop.low;high=sttop.high; top-; i=low;j=high; if(lowhigh) temp=alow; while(i!=j) while(itemp)j-; if(ij)ai=aj;i+; while(ij&aitemp)i+; if(ij)aj=ai;j-; ai=temp; top+;stto
11、p.low=low;sttop.high=i-1; top+;sttop.low=i+1;sttop.high=high; 時間部分代碼double tinsertsort(int a,int p)int i;int bn; for(i=0;in;i+) bi=ai;large_integer m_liperffreq=0;queryperformancefrequency(&m_liperffreq); large_integer m_liperfstart=0; queryperformancecounter(&m_liperfstart);insertsort(b,p);large_in
12、teger liperfnow=0; queryperformancecounter(&liperfnow); double time=liperfnow.quadpart - m_liperfstart.quadpart; time/=m_liperffreq.quadpart;if(p!=6)disp(b);getchar();printf(n用直接插入排序法用的時間為%f秒;,time);file *fp; fp=fopen(直接插入排序.txt,w); for(i=0;in;i+) fprintf(fp,%d ,bi); fclose(fp);return(time);double t
13、selectsort(int a,int p)int i;int bn;for(i=0;in;i+)bi=ai;large_integer m_liperffreq=0;queryperformancefrequency(&m_liperffreq); large_integer m_liperfstart=0; queryperformancecounter(&m_liperfstart);selectsort(b,p);if(p!=6)disp(b);getchar();large_integer liperfnow=0; queryperformancecounter(&liperfno
14、w); double time=liperfnow.quadpart - m_liperfstart.quadpart; time/=m_liperffreq.quadpart;printf(n用直接選擇排序法用的時間為%f秒;,time);file *fp; fp=fopen(直接選擇排序.txt,w);for(i=0;in;i+) fprintf(fp,%d ,bi);fclose(fp);return(time);double tbubblesort(int a,int p)int i;int bn;for(i=0;in;i+)bi=ai;large_integer m_liperffr
15、eq=0;queryperformancefrequency(&m_liperffreq); large_integer m_liperfstart=0; queryperformancecounter(&m_liperfstart);bubblesort(b,p);large_integer liperfnow=0; queryperformancecounter(&liperfnow); double time=liperfnow.quadpart - m_liperfstart.quadpart; time/=m_liperffreq.quadpart;if(p!=6)disp(b);g
16、etchar();printf(n用冒泡排序法用的時間為%f秒;,time);file *fp; fp=fopen(冒泡排序.txt,w); for(i=0;in;i+) fprintf(fp,%d ,bi);fclose(fp);return(time);double theapsort(int a,int n,int p) int i;int bn;for(i=0;in;i+)bi=ai;large_integer m_liperffreq=0;queryperformancefrequency(&m_liperffreq); large_integer m_liperfstart=0;
17、queryperformancecounter(&m_liperfstart);heapsort(b,n,p);large_integer liperfnow=0; queryperformancecounter(&liperfnow); double time=liperfnow.quadpart - m_liperfstart.quadpart; time/=m_liperffreq.quadpart;if(p!=6)disp(b);getchar();printf(n用堆排序法用的時間為%f秒;,time);file *fp; fp=fopen(堆排序.txt,w);for(i=0;in
18、;i+) fprintf(fp,%d ,bi);fclose(fp);return(time);double tquicksort(int a,int n,int p)int i;int bn; for(i=0;in;i+) bi=ai;large_integer m_liperffreq=0;queryperformancefrequency(&m_liperffreq); large_integer m_liperfstart=0; queryperformancecounter(&m_liperfstart);quicksort(b,n,p);large_integer liperfno
19、w=0; queryperformancecounter(&liperfnow); double time=liperfnow.quadpart - m_liperfstart.quadpart; time/=m_liperffreq.quadpart;if(p!=6) disp(b);getchar(); printf(n用快速排序法用的時間為%f秒;,time);file *fp;fp=fopen(快速排序.txt,w); for(i=0;in;i+) fprintf(fp,%d ,bi); fclose(fp); return(time);時間數(shù)組的冒泡排序void bublesort(
20、double a) int i,j; double temp; for(i=1;i=i;j-) if(aj+1請在上述序號中選擇一個并輸入:);主函數(shù)代碼void main() int i,p,an; srand(int)time(null); /*隨機種子*/ for(i=0;i謝謝使用!n); getchar(); break; double times5,times15;/時間數(shù)組 switch(p) case 1:tinsertsort(a,p);printf(n請按任意鍵繼續(xù).);getchar();break; case 2:tselectsort(a,p);printf(n請按任
21、意鍵繼續(xù).);getchar();break; case 3:tbubblesort(a,p);printf(n請按任意鍵繼續(xù).);getchar();break; case 4:tquicksort(a,n,p);printf(n請按任意鍵繼續(xù).);getchar();break; case 5:theapsort(a,n,p);printf(n請按任意鍵繼續(xù).);getchar();break; case 6:system(cls);times11=times1=tinsertsort(a,p);times12=times2=tselectsort(a,p); times13=times3
22、=tbubblesort(a,p);times14=times4=tquicksort(a,n,p);times15=times5=theapsort(a,n,p);getchar(); bublesort(times); printf(nn); printf(排序這組數(shù)據(jù)兩種較快的排序法分別是:n); if(times1=times11) printf(直接插入排序:%f秒!n,times1); if(times1=times12) printf(直接選擇排序:%f秒!n,times1); if(times1=times13) printf(冒泡排序:%f秒!n,times1); if(times1=times14) printf(快速排序:%f秒!n,times1); if(times1=times15) printf(堆排序:%f秒!n,times1); if(times1!=times2) if(times2=times11) printf(直接插入排序:%f秒!n,times2); if(times2=times12) printf(直接選擇排序%f秒!n,times2); if(times2=times13) printf(冒泡排序%f秒!n,times2);
溫馨提示
- 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)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 國慶節(jié)聯(lián)誼活動方案
- 現(xiàn)代經(jīng)濟環(huán)境下的市場動態(tài)與趨勢分析
- 弱電施工方案范本
- 1 有余數(shù)的除法 第二課時(說課稿)-2023-2024學(xué)年二年級下冊數(shù)學(xué)蘇教版
- 2023三年級英語下冊 Unit 1 My Body第1課時說課稿 陜旅版(三起)
- 6 有多少浪費本可避免 第一課時 說課稿-2023-2024學(xué)年道德與法治四年級下冊統(tǒng)編版001
- 2024年八年級物理下冊 12.1杠桿說課稿 (新版)新人教版001
- 《14學(xué)習(xí)有方法》(說課稿)-部編版(五四制)道德與法治二年級下冊
- 2023九年級語文下冊 第三單元 11 送東陽馬生序說課稿 新人教版001
- Unit8 We're twins(說課稿)-2023-2024學(xué)年譯林版(三起)英語三年級下冊
- 廣東省廣州市番禺區(qū)2023-2024學(xué)年七年級上學(xué)期期末數(shù)學(xué)試題
- 智研咨詢發(fā)布:2024年中國MVR蒸汽機械行業(yè)市場全景調(diào)查及投資前景預(yù)測報告
- IF鋼物理冶金原理與關(guān)鍵工藝技術(shù)1
- 煙花爆竹重大危險源辨識AQ 4131-2023知識培訓(xùn)
- 銷售提成對賭協(xié)議書范本 3篇
- 企業(yè)動火作業(yè)安全管理制度范文
- 六年級語文老師家長會
- EPC項目階段劃分及工作結(jié)構(gòu)分解方案
- 《跨學(xué)科實踐活動4 基于特定需求設(shè)計和制作簡易供氧器》教學(xué)設(shè)計
- 2024-2030年汽車啟停電池市場運行態(tài)勢分析及競爭格局展望報告
- 術(shù)后病人燙傷不良事件PDCA循環(huán)分析
評論
0/150
提交評論