forked from fineanmol/Hacktoberfest2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.cpp
51 lines (45 loc) · 940 Bytes
/
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
#include<bits/stdc++.h>
using namespace std;
void display(vector<int> A, int n){
cout<<endl;
for(auto i:A)
cout<<i<<" ";
}
void Sh_S(vector<int> &A, int n){
int interval=1;
while(interval<n/3)
{
interval=(interval*3)+1;
}
while(interval>=1)
{
for(int i=interval;i<n;i++)
{
int key=A[i];
int j=i-interval;
while(j>=0 && A[j]>key)
{
A[j+interval]=A[j];
j=j-interval;
}
A[j+interval]=key;
display(A,n);
cout<<endl<<interval<<endl;///
}
interval=(interval-1)/3;
}
}
int main(){
vector<int> V;
int ch,n;
cout<<"size: ";
cin>>n;
cout<<"ENTER ARRY: ";
for(int i=0;i<n;i++)
{
cin>>ch;
V.push_back(ch);
}
Sh_S(V,n);
display(V,n);
}