-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (50 loc) · 1.25 KB
/
main.cpp
File metadata and controls
68 lines (50 loc) · 1.25 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
#include <iostream>
#include <iomanip>
#include "sorts/quicksort.cpp"
#include "sorts/merge.cpp"
#include "sorts/gnome.cpp"
#include "sorts/selection.cpp"
#include "sorts/insertion.cpp"
#include "sorts/cocktail.cpp"
#include "sorts/bubble.cpp"
const int SIZE = 6;
void printArray(int * array, int size);
int * composeArray(int size);
int main() {
int * unsortedArray = composeArray(SIZE);
std::cout << "unsorted: ";
printArray(unsortedArray, SIZE);
// clock_t tStart = clock();
int * sortedArray = insertion(unsortedArray, SIZE);
std::cout << std::endl << "sorted: ";
printArray(sortedArray, SIZE);
// std::cout << std::endl;
// std::cout << "time: " << (double)(clock() - tStart)/CLOCKS_PER_SEC;
delete[] unsortedArray;
return 0;
}
/**
* Returns an array filled with random digits from 0 to 100.
*
* @param size
* @return
*/
int * composeArray(int size) {
int *arr = new int[size];
srand((unsigned)time(nullptr));
for (int i(0); i < SIZE; i++) {
arr[i] = (rand() % 100);
}
return arr;
}
/**
* Prints an array.
*
* @param array
* @param size
*/
void printArray(int *array, int size) {
for (int i(0); i < size; i++) {
std::cout << std::setw(2) << array[i] << " ";
}
}