a[i]=rand()%(Total*10);
QuickSort(a,0,Total-1);
printf("QuickSort:
\n");
Print(a,Total);
end5=clock();
printf("TheRunningTimeofQuickSort:
%ld\n",end5-end4);
return0;
}
(三)程序运行结果:
(1)将Total定义为10,输出结果为:
Data:
4167340692478586264
InsertionSort:
0243441586264676978
TheRunningTimeofInsertionSort:
0
ShellSort:
0243441586264676978
TheRunningTimeofShellSort:
5
HeapSort:
0243441586264676978
TheRunningTimeofHeapSort:
0
MergeSort:
0243441586264676978
TheRunningTimeofMergeSort:
1
QuickSort:
0243441586264676978
TheRunningTimeofQuickSort:
0
Pressanykeytocontinue
(2)将Total定义为100,输出结果为:
Data:
41467334500169724478358962464705145281827961491995942827436
391604902153292382421716718895447726771538869912667299358947
038113223336736641417112538685476446627573785972374152977831
63519084228810640942264648446805890729370350610139354862962
38495475684096637693130894443962632353753811882929541
InsertionSort:
635353740418284101106118141145153169190253264281288292299
308316322323333334350358370376382391393421436439446447464467
478491500529537538538541547548604623626629644648662664667673
703705711716718723724726729741756757771778805811827827840842
859868869890894895902912929931942942944954961962966995
TheRunningTimeofInsertionSort:
5
ShellSort:
635353740418284101106118141145153169190253264281288292299
308316322323333334350358370376382391393421436439446447464467
478491500529537538538541547548604623626629644648662664667673
703705711716718723724726729741756757771778805811827827840842
859868869890894895902912929931942942944954961962966995
TheRunningTimeofShellSort:
6
HeapSort:
635353740418284101106118141145153169190253264281288292299
308316322323333334350358370376382391393421436439446447464467
478491500529537538538541547548604623626629644648662664667673
703705711716718723724726729741756757771778805811827827840842
859868869890894895902912929931942942944954961962966995
TheRunningTimeofHeapSort:
10
MergeSort:
635353740418284101106118141145153169190253264281288292299
308316322323333334350358370376382391393421436439446447464467
478491500529537538538541547548604623626629644648662664667673
703705711716718723724726729741756757771778805811827827840842
859868869890894895902912929931942942944954961962966995
TheRunningTimeofMergeSort:
18
QuickSort:
635353740418284101106118141145153169190253264281288292299
308316322323333334350358370376382391393421436439446447464467
478491500529537538538541547548604623626629644648662664667673
703705711716718723724726729741756757771778805811827827840842
859868869890894895902912929931942942944954961962966995
TheRunningTimeofQuickSort:
15
Pressanykeytocontinue
(3)将Total定义为10000,输出结果为(为了输出方便,不输出原始数据和排序后的结果):
Data:
InsertionSort:
TheRunningTimeofInsertionSort:
239
ShellSort:
TheRunningTimeofShellSort:
173
HeapSort:
TheRunningTimeofHeapSort:
9
MergeSort:
TheRunningTimeofMergeSort:
4
QuickSort:
TheRunningTimeofQuickSort:
21
Pressanykeytocontinue
(4)将Total定义为50000,输出结果为(为了输出方便,不输出原始数据和排序后的结果):
Data:
InsertionSort:
TheRunningTimeofInsertionSort:
5982
ShellSort:
TheRunningTimeofShellSort:
5201
HeapSort:
TheRunningTimeofHeapSort:
46
MergeSort:
TheRunningTimeofMergeSort:
24
QuickSort:
TheRunningTimeofQuickSort:
114
Pressanykeytocontinue
实验收获:
通过对较多的数据排序可以发现,在需要排序的数据量较少的时候,快速排序、归并排序和堆排序的优势并不明显,但是在需要排序的数据量十分大的时候,快速排序、归并排序和堆排序的效率十分高,远远高于插入排序和希尔排序。
通过此次上机实验,巩固了各种排序方法,同时练习了编写程序的方法。
增强了对各种排序算法的理解,同时加深了对在需要处理的数据量非常大的时候,算法的效率对结果的产生十分的重要。