Shell sort

Updated surender_kumar 0 Tallied Votes 176 Views Share

Hello friends, I am new participant in daniweb
Here is the fantastic coding of SHEEL SORT..

#include<stdio.h>
    #include<conio.h>
    void main()
    {
    int i,n,j,gap,temp,a[10];
    clrscr();
    printf("How many numbers:=");
    scanf("%d",&n);
    printf("Enter %d numbers\n\n",n);
    for(i=0;i<n;i++)
    {
    printf("Enter a[%d]:",i);
    scanf("\n%d",&a);
    }
    for(gap=n/2;gap>0;gap=gap/2)
    {
    for(i=0;i<n;i=i+gap)
    {
    temp=a;
    for(j=i;j>0&&a[j-gap]>temp;j=j-gap)
    {
    a[j]=a[j-gap];
    }
    a[j]=temp;
    }
    }
    printf("Done with sort\n");
    for(i=0;i<n;i++)
    printf("%d\n",a);
    getch();
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.