-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell_sort.cpp
More file actions
62 lines (47 loc) · 1.01 KB
/
shell_sort.cpp
File metadata and controls
62 lines (47 loc) · 1.01 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
61
62
#include<iostream>
using namespace std;
void shell_sort(int a[],int n)
{
int gap,i,j,k,temp;
gap=n/2;
for(i=gap ; i>0 ; i=i/2)
{
for(j=i;j<n;j++)
{
for( k=j-i ; k>=0 ; k=k-i )
{
if (a[k+i] >= a[k])
{
break;
}
else
{
temp=a[k];
a[k]=a[k+i];
a[k+i]=temp;
}
}
}
}
}
int main()
{
int a[100],n;
cout<<"Total number of elements : " ;
cin>>n;
cout<<endl;
cout<<"Enter the elements : " <<endl;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<endl;
shell_sort(a,n);
cout<<"Elements after shell sort : ";
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
return 0;
}