?? readme.txt
字號:
此程序改自算法課的一個作業,用四種不同的算法,對隨機生成的n個數排序(n取值500至5000),并重復n遍,最后統計平均比較次數。本在xp下用vc6編寫,現在修改為Ubuntu下gcc編譯。./sort 運行,程序會詢問n的值;或者./sort 后面直接接n的值,可以多個,如./sort 500 1000 。Update at Mar.20 2009Add main_function 's argumentshave a test of gcc -O3 and it runs faster/*************實例****************************/roc@roc-laptop:~/proj/sort$ makegcc -c -O3 prepair.cgcc -c -O3 sort.csort.c: In function ‘main’:sort.c:61: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_resultgcc -c -O3 sortAchieve.cgcc -o sort prepair.o sort.o sortAchieve.orm *.oroc@roc-laptop:~/proj/sort$ ./sort 1000 5000*******Now No.1 section(1000 random numbers):10% 20% 30% 40% 50% 60% 70% 80% 90% 100% Now print the average times of comparison each sort_algorithm take to deal with 1000 random numbersSELECTIONSORT,INSERTIONSORT, BOTTOMUPSORT, MERGESORT, QUICKSORT 499500.00, 244281.41, 8728.69, 8704.53, 11012.40, ////Totall cost of time:0 minutes ,3 seconds//////*******Now No.2 section(5000 random numbers):2% 4% 6% 8% 10% 12% 14% 16% 18% 20% 22% 24% 26% 28% 30% 32% 34% 36% 38% 40% 42% 44% 46% 48% 50% 52% 54% 56% 58% 60% 62% 64% 66% 68% 70% 72% 74% 76% 78% 80% 82% 84% 86% 88% 90% 92% 94% 96% 98% 100% Now print the average times of comparison each sort_algorithm take to deal with 5000 random numbersSELECTIONSORT,INSERTIONSORT, BOTTOMUPSORT, MERGESORT, QUICKSORT 12497500.00, 6261454.41, 56826.94, 55233.00, 71107.11, ////Totall cost of time:3 minutes ,58 seconds//////
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -