//implement shell sorting
#include<iostream.h>
#include<math.h>
#include<conio.h>
const int size=10;
void main()
{
int a[size],gap,i,j,temp;
clrscr();
cout<<"\n\Enter elements in array\n";
for(i=0;i<size;i++)
cin>>a[i];
gap=size/2;
while(gap>0)
{
i=gap;
while(i<size)
{
temp=a[i];
j=i;
while(j>=gap && temp<a[j-gap])
{
a[j]=a[j-gap];
j=j-gap;
}
a[j]=temp;
i++;
}
gap=ceil(gap/2);
}
i=0;
cout<<"\nsorted array by shell sorting is\n";
while(i<size)
{
cout<<"\na["<<i<<"]"<<a[i];
i++;
}
getch();
}
*******output*******
#include<iostream.h>
#include<math.h>
#include<conio.h>
const int size=10;
void main()
{
int a[size],gap,i,j,temp;
clrscr();
cout<<"\n\Enter elements in array\n";
for(i=0;i<size;i++)
cin>>a[i];
gap=size/2;
while(gap>0)
{
i=gap;
while(i<size)
{
temp=a[i];
j=i;
while(j>=gap && temp<a[j-gap])
{
a[j]=a[j-gap];
j=j-gap;
}
a[j]=temp;
i++;
}
gap=ceil(gap/2);
}
i=0;
cout<<"\nsorted array by shell sorting is\n";
while(i<size)
{
cout<<"\na["<<i<<"]"<<a[i];
i++;
}
getch();
}
*******output*******
No comments:
Post a Comment