-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell sort.c
40 lines (40 loc) · 905 Bytes
/
shell sort.c
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
#include <stdio.h>
void shellsort(int arr[], int num)
{
int i, j, k, tmp;
for (i = num / 2; i > 0; i = i / 2)
{
for (j = i; j < num; j++)
{
for(k = j - i; k >= 0; k = k - i)
{
if (arr[k+i] >= arr[k])
break;
else
{
tmp = arr[k];
arr[k] = arr[k+i];
arr[k+i] = tmp;
}
}
}
}
}
int main()
{
int arr[30];
int i, num;
printf("Enter total no. of elements : ");
scanf("%d", &num);
printf("\nEnter %d numbers: ", num);
for (i=0;i<num;i++)
{
scanf("%d", &arr[i]);
}
shellsort(arr, num);
printf("\nSorted array is: ");
for (i=0;i<num;i++)
printf("%d ", arr[i]);
printf("\n");
return 0;
}