Shell Sort


        Write a program to perform shell sort.

      /* Prg to perform shell short. */

   /* In this shell sort the element will be sort in descending order. */

   #include<stdio.h>

   #include<conio.h>

   void ss(int[], int, int);

   main()

   {

/*here ne means number of elemnts in array.*/

/*here a means array.*/

/*here bs means shell sort. */

/*here dis means distance sort. */

int a[50],ne,i, dist;

printf ("Enter how many elements you wants to perform shell sort = ");

scanf("%d",&ne);

printf ("Enter the elements in array :-\n");

for (i=0;i<ne;i++)

{

    scanf ("%d",&a[i]);

}

printf ("Enter distance value to perform shell sort = ");

scanf ("%d",&dist);

ss(a,dist,ne);

printf ("Elements after sort :-\n");

for (i=0;i<ne;i++)

{

    printf("%d\t",a[i]);

}

    }

    void ss (int a[],int dis, int ne)

    {

  int pass, element, data;

  while(dis > 0)

  {

    for(pass=dis; pass<ne; pass++) // to select element.

      {

  data=a[pass];

  for(element=pass-1;element>=0 && data <= a[element];element--) // comparision with data to perform shifting

{

a[element + 1] = a[element];

}

a[element+1]=data;

    }

    dis=dis-2;

}

    }