-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshell.cpp
101 lines (93 loc) · 2.23 KB
/
shell.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
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
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
void vstavka(int *arrayPtr, int length) // ?????????? ?????????
{
int temp, // ????????? ?????????? ??? ???????? ???????? ???????? ???????????? ???????
item; // ?????? ??????????? ????????
for (int counter = 1; counter < length; counter++)
{
temp = arrayPtr[counter]; // ?????????????? ????????? ?????????? ??????? ????????? ???????? ???????
item = counter-1; // ?????????? ?????? ??????????? ???????? ???????
while(item >= 0 && arrayPtr[item] > temp) // ???? ?????? ?? ????? 0 ? ?????????? ??????? ??????? ?????? ????????
{
arrayPtr[item + 1] = arrayPtr[item]; // ???????????? ????????? ???????
arrayPtr[item] = temp;
item--;
}
}
}
int fibonacci(int number)
{
if (number == 0 || number == 1)
return (1);
return (fibonacci(number - 1) + fibonacci(number - 2));
}
int nextstep(int prev)
{
int b = prev;
double i = b / 2;
// cout << b << i << endl;
while (i / b > 1.35)
{
b = b - 1;
cout << "smth" << endl;
}
return (b);
}
int getj(int step)
{
return (pow(3, step) - 1 / 2);
}
int getbigj(int n)
{
for (int i = 0; i < n; i++)
{
if ((pow(3, i) - 1) / 2 > n)
return (i - 1);
}
}
int main()
{
int i, j, step;
int count = 0;
int n;
cin >> n;
int *mass = new int[n];
int copies = 0;
int compare = 0;
int veryj = getbigj(n);
//for (i = n - 1; i >= 0; i--)
// mass[n - i - 1] = i;
for (i = 0; i < n; i++)
mass[i] = rand();
cout << "not sorted massive" << endl;
// for (i = 0; i < n; i++)
// cout << mass[i] << endl;
// cout << "~~~~~~~~~~~~~~~~~~" << endl;
int tmp;
for (step = getj(veryj); step > 0; step = getj(veryj - ++count), compare++)
{
cout << "step " << step << endl;
for (i = step; i < n && compare++; i++)
{
tmp = mass[i];
copies++;
for (j = i; j >= step; j -= step, compare++)
{
if (tmp < mass[j - step] && copies++ && compare++)
mass[j] = mass[j - step];
else
break;
}
mass[j] = tmp;
copies++;
}
}
for (int i = 0; i < n; i++)
cout << i <<" " <<mass[i] << endl;
cout << copies << " " << compare << endl;
delete[] mass;
return (0);
}