-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
106 lines (94 loc) · 3.88 KB
/
main.cpp
File metadata and controls
106 lines (94 loc) · 3.88 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
100
101
102
103
104
105
106
#include <iostream>
#include <chrono>
#include "cmake-build-debug/N2Algorithms.h"
#include "cmake-build-debug/NLogNAlgorithms.h"
#include "cmake-build-debug/Utility.h"
using namespace std;
using namespace chrono;
int main() {
unsigned int size = 100000;
int * unsortedArray = Utility::randomArrayGenerator(&size);
cout<<"\t\t\t\t\t\t****Sorting algorithms****\n";
int option=0;
while(option !=8)
{
cout<<"\t\t\t\t\t *********menu:**********\n";
cout<<"enter:\n\t\t\t\t\t1:insertion sort 5:heap sort\n\t\t\t\t\t2:selection sort\t6:quick sort\n\t\t\t\t\t3:bubble sort 7:print sorted array\n\t\t\t\t\t4:merge sort\t8:quit\n";
cout<<"answer:";
cin>>option;
switch(option)
{
case 1:
{cout<<"*****************************************\n";
auto start = high_resolution_clock::now();
N2Algorithms::insertionSort(unsortedArray, size);
auto stop = high_resolution_clock::now();
auto duration = duration_cast<nanoseconds>(stop - start);
cout << "Time taken by insertion sort process: "
<< duration.count() << " nanoseconds \n" << endl;
cout<<"*****************************************\n";
break;
}
case 2:
{auto start = high_resolution_clock::now();
N2Algorithms::selectionSort(unsortedArray, size);
auto stop = high_resolution_clock::now();
auto duration = duration_cast<nanoseconds>(stop - start);
cout << "Time taken by selection process: "
<< duration.count() << " nanoseconds \n" << endl;
cout<<"*****************************************\n";
break;
}
case 3:
{auto start = high_resolution_clock::now();
N2Algorithms::bubbleSort(unsortedArray, size);
auto stop = high_resolution_clock::now();
auto duration = duration_cast<nanoseconds>(stop- start);
cout << "Time taken by bubble sort process: "
<< duration.count() << " nanoseconds \n" << endl;
cout<<"*****************************************\n";
break;
}
case 4:
{auto start = high_resolution_clock::now();
NLogNAlgorithms::mergeSort(unsortedArray,0,size-1);
auto stop = high_resolution_clock::now();
auto duration = duration_cast<nanoseconds>(stop- start);
cout << "Time taken by merge sort process: "
<< duration.count() << " nanoseconds \n" << endl;
cout<<"*****************************************\n";
break;
}
case 5:
{auto start = high_resolution_clock::now();
NLogNAlgorithms::heapSort(unsortedArray, size);
auto stop = high_resolution_clock::now();
auto duration= duration_cast<nanoseconds>(stop- start);
cout << "Time taken by heap sort process: "
<< duration.count() << " nanoseconds \n" << endl;
cout<<"*****************************************\n";
break;
}
case 6:
{ auto start= high_resolution_clock::now();
NLogNAlgorithms::quickSort(unsortedArray,0,size-1);
auto stop= high_resolution_clock::now();
auto duration= duration_cast<nanoseconds>(stop- start);
cout << "Time taken by quick sort process: "
<< duration.count() << " nanoseconds \n" << endl;
cout<<"*****************************************\n";
break;
}
case 7:
{cout<<"sorted array\n";
Utility::displayArray(unsortedArray, size);
break;
}
case 8:
exit(0);
default:
cout<<"enter from 1 to 8";
}
}
return 0;
}