-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
118 lines (77 loc) · 2.64 KB
/
main.cpp
File metadata and controls
118 lines (77 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// main.cpp
// sort
//
////I Ayne Delgado have not used any code other than my own (or that in the textbook) for this project.
//I also have not used any function or data-structure from the Standard-Template Library.
//I understand that any violation of this disclaimer will result in a 0 for the project.
//
#include <iostream>
#include <ctime>
#include "Sort.h"
using namespace std;
//----------------------CONSTANTS----------------------
int const BIG = 1000;
int const GIANT = 1000;
double const SEC_TO_MILLISEC=1000;
int const PRECISION = 3;
int main()
{
Sort sort1(BIG);
sort1.init_array();
Sort sort2(BIG);
sort2.init_array();
Sort sort3(BIG);
sort3.init_array();
Sort sort4(BIG);
sort4.init_array();
clock_t start1 = clock();
for(int i = 0; i<GIANT; i++)
{
sort1.init_array();
sort1.insertion_sort();
}
clock_t end1 = clock();
clock_t diff1 = end1-start1;
clock_t start2 = clock();
for(int i = 0; i<GIANT; i++)
{
sort2.init_array();
sort2.selection_sort();
}
clock_t end2 = clock();
clock_t diff2 = end2-start2;
clock_t start3 = clock();
for(int i = 0; i<GIANT; i++)
{
sort3.init_array();
sort3.merge_sort();
}
clock_t end3 = clock();
clock_t diff3 = end3-start3;
clock_t start4 = clock();
for(int i =0; i<GIANT; i++)
{
sort4.init_array();
sort4.quick_sort();
}
clock_t end4 = clock();
clock_t diff4 = end4-start4;
//calculate clocks per tick to milliseceonds for one loop per sort
double time1 = ((((double)diff1)/CLOCKS_PER_SEC)*SEC_TO_MILLISEC)/GIANT;
double time2 = ((((double)diff2)/CLOCKS_PER_SEC)*SEC_TO_MILLISEC)/GIANT;
double time3 = ((((double)diff3)/CLOCKS_PER_SEC)*SEC_TO_MILLISEC)/GIANT;
double time4 = ((((double)diff4)/CLOCKS_PER_SEC)*SEC_TO_MILLISEC)/GIANT;
//show 3 decimal places
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(PRECISION);
//display time each sort took for 1 loop in milliseconds for an array of size sort.get_size
cout<<"The insertion sort took: "<<time1<<" milliseconds, for an array of size "<< sort1.get_size() <<endl;
cout<<"The selection sort took: "<<time2<<" milliseconds, for an array of size "<< sort2.get_size() <<endl;
cout<<"The merge sort took: "<<time3<<" milliseconds, for an array of size "<< sort3.get_size() <<endl;
cout<<"The quick sort took: "<<time4<<" milliseconds, for an array of size "<< sort4.get_size();
cout<<endl;
//system("PAUSE");
return 0;
}