-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellsort.cpp
More file actions
39 lines (31 loc) · 809 Bytes
/
shellsort.cpp
File metadata and controls
39 lines (31 loc) · 809 Bytes
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
#include<bits/stdc++.h>
using namespace std;
/***************************************ORIGINAL aUTHOR*******************************
*************************************************************************************
*************************************************************************************
*************astrainL3gi0N**********************************************************/
int main()
{
int n; cin>>n;
int arr[100];
for(int i = 0; i < n; ++i) cin>>arr[i];
int h = 0;
while(h < n){
h = 3*h + 1;
}
h = h/3;
cout<<h<<'\n';
while(h > 0){
for(int i = h; i < n; ++i){
for(int j = i; j-h >= 0 && arr[j] < arr[j-h]; j-=h){
int temp = arr[j];
arr[j] = arr[j-h];
arr[j-h] = temp;
}
}
h = h/3;
}
for(int i = 0;i < n; ++i)
cout<<arr[i]<<' ';
return 0;
}