Following Program Sort The Array Elements Using Shell Sort.
#include<iostream>
using namespace std;
main()
{
int a[100],d,n;
cout<<"Enter The No oF Elements ";
cin>>n;
cout<<"Enter The Elements\n";
for(int i=0;i<n;i++)
cin>>a[i];
for(d=n/2;d>=1;d--)
for(int i=0;i<n-d;i++)
if(a[i]>a[i+d])
{
int temp=a[i];
a[i]=a[i+d];
a[i+d]=temp;
}
cout<<"Sorted Array Is\n";
for(int i=0;i<n;i++)
cout<<a[i]<<"\t";
}
Output:
#include<iostream>
using namespace std;
main()
{
int a[100],d,n;
cout<<"Enter The No oF Elements ";
cin>>n;
cout<<"Enter The Elements\n";
for(int i=0;i<n;i++)
cin>>a[i];
for(d=n/2;d>=1;d--)
for(int i=0;i<n-d;i++)
if(a[i]>a[i+d])
{
int temp=a[i];
a[i]=a[i+d];
a[i+d]=temp;
}
cout<<"Sorted Array Is\n";
for(int i=0;i<n;i++)
cout<<a[i]<<"\t";
}
Output: