-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShell Sort.c
More file actions
49 lines (42 loc) · 813 Bytes
/
Shell Sort.c
File metadata and controls
49 lines (42 loc) · 813 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
49
/**
* @author: Ashish A Gaikwad <ash.gkwd@gmail.com>
* Shell Sort Algorithm (modified Insertion sort) in C
*/
#include <stdio.h>
#define MAX 30
int main()
{
int total, kira, series[MAX];
printf("Enter Number Of Elements:\n");
scanf("%d", &total);
for(int i=0; i<total; i++)
{
printf("Number %d: ", i+1);
scanf("%d", &series[i]);
}
for (int i = total/2; i>0; --i)
{
// Let the Partial Insertion sort begin
for(int z = i; z<total; z++)
{
for (int j = z-1; j>=0; j -= i)
{
if(series[j] > series[j+i])
{
kira = series[j];
series[j] = series[j+i];
series[j+i] = kira;
}
else break;
}
}
}
// Show sorted elements :)
printf("The Shell Sorted Result:\n");
for (int i = 0; i < total; ++i)
{
printf("%d ", series[i]);
}
printf("\n");
return 0;
}