Sunday, October 2, 2011

Shell Sort C program for Dev C++

 void shellsort(int a[],int n)  
{
int i,j,temp,inc=n/2-1;
while(inc>0)
{
for(i=inc;i<n;i++)
{
temp=a[i];
j=i-inc;
while(j>=0 && a[j]>temp)
{
a[j+inc]=a[j];
j=j-inc;
}
a[j+inc]=temp;
}
inc=inc/2;
}
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
getch();
}
int main()
{
int a[]={1,5,7,2,0,-1,5,43,23,60};
shellsort(a,10);
}

No comments:

Post a Comment