Shell Sort :

<br />#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
int a[10],n,flag,gap;
cout<<"--------Shell Sort---------"<<endl<<endl;
cout<<"Enter the size of array:"<<endl;
cin>>n;
cout<<"Enter Elements:"<<endl;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
gap=n/2;
do
{
do
{
flag=0;
for(int i=0;i<n-gap;i++)
{
if(a[i]>a[i+gap])
{
int temp = a[i];
a[i]=a[i+gap];
a[i+gap]=temp;
flag=1;
}
}
}while(flag);
}while(gap=gap/2);
cout<<endl<<"After Sorting Array is:"<<endl;
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
cout<<endl<<" @Myprogworld...!!"<<endl;
getch();
return 0;
}

Output :-
Shell sort

Leave a comment