forked from jainaman224/Algo_Ds_Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShell_Sort.cpp
More file actions
48 lines (34 loc) · 741 Bytes
/
Shell_Sort.cpp
File metadata and controls
48 lines (34 loc) · 741 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
46
47
48
// C++ implementation of Shell Sort
#include <iostream>
using namespace std;
int Shell_Sort(int array[], int size)
{
for(int gap = size / 2; gap > 0; gap /= 2)
{
for(int i = gap; i < size; i++)
{
int temp = array[i], j;
for(j = i; j >= gap && array[j - gap] > temp; j -= gap)
array[j] = array[j - gap];
array[j] = temp;
}
}
return 0;
}
void Print_Array(int array[], int size)
{
for(int i = 0; i < size; i++)
cout << array[i] << " ";
cout << endl;
}
int main()
{
int array[] = {12, 34, 54, 2, 3};
int size = 5;
Shell_Sort(array, size);
Print_Array(array, size);
return 0;
}
/* Output
2 3 12 34 54
*/