This C program sorts a given array of integer numbers using Shell Sort technique.

Shellsort, also known as Shell sort or Shell’s method, is an in-place comparison sort. It can either be seen as a generalization of sorting by exchange (bubble sort) or sorting by insertion (insertion sort). The method starts by sorting elements far apart from each other and progressively reducing the gap between them. Starting with far apart elements can move some out-of-place elements into position faster than a simple nearest neighbor exchange. Worst case time complexity is O(n

Shellsort, also known as Shell sort or Shell’s method, is an in-place comparison sort. It can either be seen as a generalization of sorting by exchange (bubble sort) or sorting by insertion (insertion sort). The method starts by sorting elements far apart from each other and progressively reducing the gap between them. Starting with far apart elements can move some out-of-place elements into position faster than a simple nearest neighbor exchange. Worst case time complexity is O(n

^{2}) and best case complexity is O(nlog(n)).Here is the source code of the C program to sort integers using Shell Sort technique. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C Program to sort an array using Shell Sort technique`

`*/`

`#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 k, num;

printf("Enter total no. of elements : ");

scanf("%d", &num);

printf("\nEnter %d numbers: ", num);

for (k = 0 ; k < num; k++)

`{`

scanf("%d", &arr[k]);

`}`

shellsort(arr, num);

printf("\n Sorted array is: ");

for (k = 0; k < num; k++)

printf("%d ", arr[k]);

return 0;

`}`

$ gcc shellsort.c -o shellsort $ ./shellsort Enter total no. of elements : 10 Enter numbers : 36 432 43 44 57 63 94 3 5 6 Sorted array is : 3 5 6 36 43 44 57 63 94 432

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data Structures and Algorithms.