C Program to sort the string, using shell sort technique.

C Program to sort the string, using shell sort technique. Shell sort is the one of the oldest sorting technique, quite well for all types of arrays in c. The shell sort is a “diminishing increment sort”, better known as a “comb sort” to the unwashed programming masses. The algorithm makes multiple passes through the list, and each time sorts a number of equally sized sets using the insertion sort . The size of the set to be sorted gets larger with each pass through the list, until the set consists of the entire list. This sets the insertion sort up for an almost-best case run each iteration with a complexity that approaches O(n) . Read more about C Programming Language .

* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
* Happy Coding

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void shell_sort(char *chars, int c) {

register int i, j, space, k;
char x, a[5];

a[0]=9; a[1]=5; a[2]=3; a[3]=2; a[4]=1;

for(k=0; k < 5; k++) {
space = a[k];
for(i=space; i < c; ++i) {
x = chars[i];
for(j=i-space; (x < chars[j]) && (j >= 0); j=j-space)
chars[j+space] = chars[j];
chars[j+space] = x;

int main() {
char string[300];
printf("Enter a string:");
shell_sort(string, strlen(string));
printf("The sorted string is: %s.n", string);
return 0;
Read more Similar C Programs
Array In C

Sorting Techniques

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

Leave a Reply