




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、實(shí)驗(yàn)課題一:【用C描述課本的同學(xué)】有以下結(jié)構(gòu)體構(gòu)成的數(shù)組:struct StudentInfochar ID10;char * name;float score;StuInfo12=0800301105, JACK, 95,0800201505, LUN, 85,0400820115, MARY, 75.5,0400850122, KATE, 78.9,0500201011, LILI, 88,0800401105, JACK, 96,0600830105, JAN, 98.4,0952520012, SAM, 75,9721000045, OSCAR, 64,0700301105, JACK
2、, 97,0458003312, ZOE, 68.9,0400830211, BOBI, 87.6 ; 1 使用直接插入的排序方法按照學(xué)號的順序?qū)σ陨蠑?shù)組進(jìn)行排序(遞增);2 分別用歸并排序和快速排序按照姓名的順序?qū)σ陨蠑?shù)組進(jìn)行排序(遞增),有3人的名字是JACK,注意觀察排序是否穩(wěn)定。程序1#include#include#includetypedef struct StudentInfo ElementType;struct StudentInfochar ID11;char *name;double score;StuInfo12=0800301105,JACK,95,080020150
3、5,LUN,85,0400820115,MARY,75.05,0400850122,KATE,78.9,0500201011,LILI,88,0800401105,JACK,96,0600830105,JAN,98.4,0952520012,SAM,75,9721000045,OSCAR,64,0700301105,JACK,97,0458003312,ZOE,68.9,0400830211,BOBI,87.6;void InsertionSort(ElementType A,int N)int j,P;ElementType Tmp;for(P=1;P0&strcmp(Aj-1.ID,Tmp
4、.ID)0;j-)Aj=Aj-1;Aj=Tmp;void InsertionSort2(ElementType A,int N)int j,P;ElementType Tmp;for(P=1;P0&strcmp(A,T)0;j-)Aj=Aj-1;Aj=Tmp;void Merge (ElementType A,ElementType TmpArray,int Lpos,int Rpos,int RightEnd)int i,LeftEnd,NumElements,Tmpos;LeftEnd=Rpos-1;Tmpos=Lpos;NumElements=RightEn
5、d-Lpos+1;while(Lpos=LeftEnd&Rpos=RightEnd)if(strcmp(AL,AR)=0)TmpArrayTmpos+=ALpos+;elseTmpArrayTmpos+=ARpos+;while(Lpos=LeftEnd)TmpArrayTmpos+=ALpos+;while(Rpos=RightEnd)TmpArrayTmpos+=ARpos+;for(i=0;iNumElements;i+,RightEnd-)ARightEnd=TmpArrayRightEnd;void MSort(ElementType A,Elemen
6、tType TmpArray,int Left,int Right)int center;if(Left0)Swap(&ALeft,&ACenter);if(strcmp(AL,AR)0)Swap(&ALeft,&ARight);if(strcmp(AC,AR)0)Swap(&ACenter,&ARight);Swap(&ACenter,&ARight-1);return ARight-1;#define Cutoff 3void Qsort(ElementType A,int Left,int Right)int i,j
7、;ElementType Pivot;if(Left+Cutoff=Right)Pivot=Median3(A,Left,Right);i=Left;j=Right-1;for(;)while(strcmp(A+,P)0)if(ij)Swap(&Ai,&Aj);elsebreak;Swap(&Ai,&ARight-1);Qsort(A,Left,i-1);Qsort(A,i+1,Right);elseInsertionSort2(A+Left,Right-Left+1);void PrintInfo()int i;printf( 學(xué)號ID 姓名 分?jǐn)?shù)n);for(
8、i=0;i12;i+)printf(%-15s,StuInfoi.ID);printf(%-10s,StuI);printf(%.1fn,StuInfoi.score);void main()printf(原順序?yàn)椋簄n);PrintInfo();printf(用插入法排序?yàn)椋簄n);InsertionSort(StuInfo,12);PrintInfo();printf(用歸并法排序?yàn)椋簄n);Mergsort(StuInfo,12);PrintInfo();printf(用快速法排序?yàn)椋簄n);Qsort(StuInfo,0,11);PrintInfo();程序2#inc
9、lude#include#include#include#define Cutoff (3)struct StudentInfochar ID10;char * name;double score;StuInfo12=0800301105, JACK, 95,0800201505, LUN, 85,0400820115, MARY, 75.5,0400850122, KATE, 78.9,0500201011, LILI, 88,0800401105, JACK, 96,0600830105, JAN, 98.4,0952520012, SAM, 75,0721000045, OSCAR, 6
10、4,0700301105, JACK, 97,0458003312, ZOE, 68.9,0400830211, BOBI, 87.6 ,; void InsertionSort(struct StudentInfo A,int N)int j,p;struct StudentInfo Tmp; for(p=1;p0&strcmp(Aj-1.ID,Tmp.ID)0 ; j-)Aj=Aj-1;Aj=Tmp;void InsertionSort1(struct StudentInfo A,int N)int j,p;struct StudentInfo Tmp; for(p=1;p0&strcmp
11、(A,T)0 ; j-)Aj=Aj-1;Aj=Tmp;void Merge(struct StudentInfo A,struct StudentInfo TmpArray,int Lpos,int Rpos,int RightEnd)int i,LeftEnd,NumElements,TmpPos;LeftEnd=Rpos-1;TmpPos=Lpos;NumElements=RightEnd-Lpos+1;while(Lpos=LeftEnd & Rpos=RightEnd)if(strcmp(AL,AR)=0)TmpArrayT
12、mpPos+=ALpos+;elseTmpArrayTmpPos+=ARpos+;while(Lpos=LeftEnd)TmpArrayTmpPos+=ALpos+;while(Rpos=RightEnd)TmpArrayTmpPos+=ARpos+; for(i=0;iNumElements;i+,RightEnd-)ARightEnd=TmpArrayRightEnd;void MSort(struct StudentInfo A,struct StudentInfo TmpArray,int Left,int Right)int Center;if(Left0) Swap(&ALeft,
13、&ACenter); if(strcmp(AL,AR)0) Swap(&ALeft,&ARight); if(strcmp(AC,AR)0) Swap(&ACenter,&ARight); Swap(&ACenter,&ARight-1); return ARight-1;void Qsort(struct StudentInfo A,int Left,int Right)int i,j; struct StudentInfo Pivot,Tmp;if(Left+Cutoff=Right)Pivot=Median3(A,L
14、eft,Right);i=Left;j=Right-1;for(;)while(strcmp(A+,P)0)if(ij) Swap(&Ai,&Aj); Tmp=Ai;Ai=Aj;Aj=Tmp;elsebreak;Swap(&Ai,&ARight-1); Qsort(A,Left,i-1);Qsort(A,i+1,Right); InsertionSort1(A+Left,Right-Left+1);void Quicksort(struct StudentInfo A,int N)Qsort(A,0,N-1);void main()int i=0;InsertionSort(StuInfo,12); for(i=0;i12;i+)printf(%s,%s,%0.1fn,StuInfoi.ID,StuI,StuInfoi.scor
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- Rev-6207-free-base-生命科學(xué)試劑-MCE
- EGR-1-IN-3-生命科學(xué)試劑-MCE
- 法律英語專業(yè)知識訓(xùn)練題集
- 能源行業(yè)各類型能源使用情況統(tǒng)計(jì)表格
- 知識競賽發(fā)言稿
- 手服務(wù)器租用采購合同
- 小吃店承包合同協(xié)議書
- 地鐵隧道襯砌防滲技術(shù)
- 三方物業(yè)服務(wù)委托合同
- 腳手架加固施工方案
- 工業(yè)旅游策劃案例
- 智能制造企業(yè)制造成熟度能力域打分表
- 《員工保密協(xié)議書》電子版正規(guī)范本(通用版)
- 城市災(zāi)害學(xué)課件-地質(zhì)災(zāi)害(1)課件
- 物流配送退出申請書
- 【學(xué)校必備】普及精神衛(wèi)生知識-中小學(xué)“世界精神衛(wèi)生日”科普講座
- 企業(yè)安全文化建設(shè)導(dǎo)則
- 鑄件(原材料)材質(zhì)報(bào)告
- 八年級語文上冊第六單元作業(yè)設(shè)計(jì) 品格與志趣
- 鐵道游擊隊(duì)測試題6.1總1文檔資料
- 電機(jī)與電氣控制技術(shù)(第2版)全套完整教學(xué)課件
評論
0/150
提交評論