Tweet
#include<stdio.h>
void swap(int *a,int x,int y)
{
int temp=*(a+x);
*(a+x)=*(a+y);
*(a+y)=temp;
}
void shellsort(int a[],int n)
{
int i,j,d=n*4/5;
while(d>=1)
{ for(i=0;i<n-d;i++)
if(a[i]>a[i+d])
swap(a,i,i+d);
if(d==1) break;
d=d*4/5;
}
}
main()
{
int i,n;
printf("\nProgram to sort an array using shell sort : \n");
printf("Enter array capacity : \n");
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
a[i]=rand()%100;
printf("Initial array : ");
for(i=0;i<n;i++)
printf("%4d",a[i]);
shellsort(a,n);
printf("\nSorted array : ");
for(i=0;i<n;i++)
printf("%4d",a[i]);
printf("\n");
}
Shell Sort Programming in C
Posted by
LAHAUL SETH
~
Shell Sort Programming in C
2011-11-29T11:00:00+05:30
LAHAUL SETH
Programming in C
|
Sorting
|
Comments
Shell Sort Programming in C
2011-11-29T11:00:00+05:30
LAHAUL SETH
Programming in C
|
Sorting
|