-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (59 loc) · 1.25 KB
/
main.cpp
File metadata and controls
60 lines (59 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
#include <stdio.h>
#include "My_sorting.h"
#include <stdlib.h>
#include <time.h>
int main() {
clock_t t;
int* arr;
int n, k;
printf("Enter the size of array: ");
scanf_s("%d", &n);
printf("Enter the kind of sorting:\n1) BubbleSort\n2) Forward sorting\n3) Quick sorting\n");
scanf_s("%d",&k);
arr = (int*)malloc(n * sizeof(int));
srand(time(NULL)); //ñèñòåìíîå âðåìÿ
for (int i = 0; i < n; i++) {
//arr[i] = rand() % 15000000;
arr[i] = n - i;
}
switch (k){
case 1:
t = clock();
BubbleSort(arr, n);
t = clock() - t;
for (int i = 0; i < n; i++) {
printf(" %d ", arr[i]);
}
printf("\n");
printf("It took me %d (%f seconds).\n",
(int)t, ((double)t) / CLOCKS_PER_SEC);
break;
case 2:
t = clock();
ForwSort(arr, n);
t = clock() - t;
for (int i = 0; i < n; i++) {
printf(" %d ", arr[i]);
}
printf("\n");
printf("It took me %d clicks (%f seconds).\n",
(int)t, ((double)t) / CLOCKS_PER_SEC);
break;
case 3:
t = clock();
QuickSort(arr, n - 1, 0);
t = clock() - t;
for (int i = 0; i < n; i++) {
printf(" %d ", arr[i]);
}
printf("\n");
printf("It took me %d clicks (%f seconds).\n",
(int)t, ((double)t) / CLOCKS_PER_SEC);
break;
default:
printf("Encorrect entering");
break;
}
free(arr);
return 0;
}