-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
71 lines (65 loc) · 2.76 KB
/
main.cpp
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
// №13 Сортировка Хоара с простым слиянием
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <omp.h>
#include <ctime>
using namespace std;
void CreateArray(double arr[], int lenght) //Генерация
{
srand((unsigned int)time(NULL));
for (int i = 0; i < lenght; i++)
{
arr[i] = rand() % 10;
}
}
void PrintArray(double* arr, int size) //Печать
{
if (size < 20)
{
for (int i = 0; i < size; i++)
{
cout << arr[i]<< " ";
}
}
return;
}
void QuickSort(int length, double array[]) //Сортировка
{
int i, j, step;
double tmp;
for (step = length / 2; step > 0; step /= 2)
for (i = step; i < length; i++)
{
tmp = array[i];
for (j = i; j >= step; j -= step)
{
if (tmp < array[j - step])
array[j] = array[j - step];
else
break;
}
array[j] = tmp;
}
}
int main(int argc, char * argv[])
{
double size;
double array[100000];
double time = 0;
cout << "Enter num's element's in array: ";
cin >> size;
CreateArray(array, size);
cout << "The Generated array: ";
PrintArray(array, size);
cout << endl;
time = clock();
QuickSort(size, array);
time = (clock() - time) / static_cast<double>(CLOCKS_PER_SEC);
cout << "Array after QuickSort: ";
PrintArray(array, size);
cout << endl;
cout << "Sequence version time: " << time << endl;
delete[] array;
return 0;
}