by Dinesh Thakur Category: Array
#include <stdio.h>

main()
{
     int arr[10];
     int i, j, n , flag= 1, gap_size,temp;
     clrscr();
     printf("\n Enter the number of elements in the array: ");
     scanf ("%d",&n);
     printf("\n Enter  numbers: ");
       for(i= 0;i< n;i++)
       {
            scanf("%d",&arr[i]);
       }
          while(flag == 1 || gap_size>1)
          {
             flag=0;
             gap_size=(gap_size+1)/2;
                    for(i=0;i<(n-gap_size);i++)
                    {
                             if(arr[i+gap_size]>arr[i])
                              {
                                   temp = arr[i+gap_size];
                                   arr[i+gap_size]=arr[i];
                                   arr[i] = temp;
                              }
                    }
         }
             printf("\n The sorted array is: \n");
   for(i=0;i<n;i++)
    {
          printf ("\t%d\t", arr [i]);
    }
          getch();
}

implement shell sort



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles