排序算法比较程序2008-04-04功能要求如下:排序算法比较: shellsort, quicksort, heapsort, mergesort 的算法实现 ,对同样数据集的排序时间比较。源代码:# include <stdio.h> # include <time.h> # define MAXSIZE 2000 typedef struct{ int key[MAXSIZE]; int length; }list; long int compCount; long int shiftCount; void menu(int *m)/*retun m*/ { int i; char menu[6][15]={"1 CREATE ","2 IMPORT ","3 SORT","4 SHOW RESULT", "5 SAVE RESULT","6 EXIT"}; clrscr(); printf("SORT COMPARE SYSTEM
"); for (i=0;i<6;i++) printf("%s
",menu[i]); printf("
Please Select (1-6):
");
printf("
MERGESORT COST TIME :%f SECONDS.",*timemerge); printf("Compare %d times.Shfit %d times.
",compCount,shiftCount); } main() { list L,LS,LQ,LH,LM; int LOCK3=0,LOCK4=0,LOCK5=0,RUN=1,LOCK41=0,LOCK42=0,LOCK43=0,LOCK44=0; int comd,r; float timeshell,timequick,timeheap,timemerge;
while(RUN==1) { start: menu(&comd); switch (comd) { case 1: create(&L); LOCK3=1; break; case 2: import(&L); LOCK3=1; goto start; case 3: if(LOCK3==0) goto start; menusort(&comd); LOCK4=1; LOCK5=1; switch (comd) { case 1: LOCK41=1; shell(L,&LS,×hell); printf("
PRESS ANY KEY TO RETURN MAIN MENU...
"); getch(); goto start; case 2: LOCK42=1; quick(L,&LQ,&timequick); printf("
PRESS ANY KEY TO RETURN MAIN MENU...
"); getch(); goto start; case 3: LOCK43=1; heap(L,&LH,&timeheap); printf("
PRESS ANY KEY TO RETURN MAIN MENU...
"); getch(); goto start; case 4: LOCK44=1; domerge(L,&LM,&timemerge); printf("
PRESS ANY KEY TO RETURN MAIN MENU...
"); getch(); goto start; case 5: LOCK41=1; LOCK42=1; LOCK43=1; LOCK44=1; shell(L,&LS,×hell); quick(L,&LQ,&timequick); heap(L,&LH,&timeheap); domerge(L,&LM,&timemerge); printf("
PRESS ANY KEY TO RETURN MAIN MENU...
"); getch(); goto start; case 6: goto start; } case 4: if(LOCK4==0) goto start; menushow(&comd); switch(comd) { case 1: if(LOCK41==0) goto start; for (r=1;r<=LS.length;r++) printf("%d",LS.key[r]); printf("
PRESS ANY KEY TO RETURN MAIN MENU...
"); getch(); goto start; case 2: if(LOCK42==0) goto start; for (r=1;r<=LQ.length;r++) printf("%d",LQ.key[r]); printf("
PRESS ANY KEY TO RETURN MAIN MENU...
"); getch(); goto start; case 3: if(LOCK43==0) goto start; for (r=1;r<=LH.length;r++) printf("%d",LH.key[r]); printf("
PRESS ANY KEY TO RETURN MAIN MENU...
"); getch(); goto start; case 4: if(LOCK44==0) goto start; for (r=1;r<=LM.length;r++) printf("%d",LM.key[r]); printf("
PRESS ANY KEY TO RETURN MAIN MENU...
"); getch(); goto start; case 6: goto start; } case 5: if(LOCK5==0) goto start; menusave(&comd); switch (comd) {
case 1: if(LOCK41==0) goto start; save(LS); break; case 2: if(LOCK42==0) goto start; save(LQ); break; case 3: if(LOCK43==0) goto start; save(LH); break; case 4: if(LOCK44==0) goto start; save(LM); break; case 6: break;