-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShell.cpp
More file actions
42 lines (42 loc) · 723 Bytes
/
Shell.cpp
File metadata and controls
42 lines (42 loc) · 723 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
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int arr1[20], n, gap;
cout << "Enter the size of array"<<endl;
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "Enter the value of " << i+1 << " of array" << endl;
cin >> arr1[i];
}
gap = n / 2;
while(gap>=1)
{
for (int j = gap; j < n; j++)
{
for (int i = j - gap; i >= 0; i - gap)
{
if (arr1[i + gap] > arr1[i])
{
break;
}
else
{
int temp = arr1[i];
arr1[i] = arr1[i + gap];
arr1[i + gap] = temp;
}
}
}
gap = gap / 2;
}
cout << "sorted array "<<endl;
for (int i = 0; i < n; i++)
{
cout << arr1[i]<<" ";
}
_getch();
return;
}