==========================================================
SHELL SORT>>
==============================================================
#include<stdio.h>
#include<conio.h>
void shellsort(int a[],int n)
{
int m,i,j,mid;
for(m=n/2;m>0;m/=2)
{ for(j=m;j<n;j++)
{ for(i=j-m;i>=0;i-=m)
{
if(a[i+m]>=a[i])
break;
else
{
mid=a[i];
a[i]=a[i+m];
a[i+m]=mid;
}
}} } }
void main()
{
int a[100],n,i;
clrscr();
printf("Enter the number of elements=\t");
scanf("%d",&n);
printf("Enter %d elements one by one:>>\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Array before sorting>>\n");
for(i=0;i<n;i++)
printf("[%d]\n",a[i]);
shellsort(a,n);
printf("Array after sorting>>\n");
for(i=0;i<n;i++)
printf("[%d]\n",a[i]);
}
SHELL SORT>>
==============================================================
#include<stdio.h>
#include<conio.h>
void shellsort(int a[],int n)
{
int m,i,j,mid;
for(m=n/2;m>0;m/=2)
{ for(j=m;j<n;j++)
{ for(i=j-m;i>=0;i-=m)
{
if(a[i+m]>=a[i])
break;
else
{
mid=a[i];
a[i]=a[i+m];
a[i+m]=mid;
}
}} } }
void main()
{
int a[100],n,i;
clrscr();
printf("Enter the number of elements=\t");
scanf("%d",&n);
printf("Enter %d elements one by one:>>\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Array before sorting>>\n");
for(i=0;i<n;i++)
printf("[%d]\n",a[i]);
shellsort(a,n);
printf("Array after sorting>>\n");
for(i=0;i<n;i++)
printf("[%d]\n",a[i]);
}
No comments:
Post a Comment