Hi,

I was trying to code the shell sort algorithm ,which compares data over distances of n/2,then n/4,n/8 and so on till the array finally gets sorted .As far I understood I implemented the code as follows but it doesn't seem to work.Can someone help!

here is the c code

```
void shellsort(int a[],int n)
{
int i,x,temp;
int inc=n/2;
int lim;
lim=n-inc;
while(inc>0)
{
lim=n-inc;
for(i=0;i<lim;i++)
{
if(a[i]>a[i+inc])
{
temp=a[i];
a[i]=a[i+inc];
a[i+inc]=temp;
}
}
inc=inc/2;
}
printf("\nThe sorted array is:");
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
```

ouput

-----

Enter the number of elements:5

Enter the elements:5 4 3 2 1

The sorted order is:3 2 4 5 2368400

Please Help!