forked from TheAlgorithms/C-Plus-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShell Sort.cpp
More file actions
45 lines (42 loc) · 682 Bytes
/
Copy pathShell Sort.cpp
File metadata and controls
45 lines (42 loc) · 682 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
40
41
42
43
44
45
#include<iostream>
using namespace std;
int main()
{
int size=10;
int array[size];
// Input
cout<<"\nHow many numbers do want to enter in unsorted array : ";
cin>>size;
cout<<"\nEnter the numbers for unsorted array : ";
for (int i = 0; i < size; i++)
{
cin>>array[i];
}
// Sorting
for (int i = size/2; i>0 ; i=i/2)
{
for (int j = i; j <size ; j++)
{
for (int k = j-i; k>=0; k=k-i)
{
if (array[k]<array[k+i])
{
break;
}
else
{
int temp=array[k+i];
array[k+i]=array[k];
array[k]=temp;
}
}
}
}
// Output
cout<<"\nSorted array : ";
for (int i = 0; i < size; ++i)
{
cout<<array[i]<<"\t";
}
return 0;
}