Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Program to Implement Shell Sort in CPP (C plus plus)

Program to Implement Shell Sort in CPP (C plus plus)

In this tutorial, we will learn about the Program to Implement the Shell Sort in CPP (C plus plus).

#include<iostream>
 
using namespace std;
 
void sorting(int a[],int n)
{
    int tmp;
	int i;
	int j;
    int g;
 
    for(g=n/2;g>0;g/=2)
    {
        for(i=g;i<n;i+=1)
        {
            tmp=a[i];
            for(j=i;j>=g&&a[j-g]>tmp;j-=g)
                a[j]=a[j-g];
            
            a[j]=tmp;
        }
    }
}
 
int main()
{
    int array[20];
	int i;
	int num;
    
    cout<<"Please enter the number of values: ";
    cin>>num;
        
    cout<<"Please enter values into array "<<endl;
    
    for(i=0;i<num;++i)
        cin>>array[i];
 
    sorting(array,num);
 
    cout<<endl<<"Array after shell sorting is: "<<endl;
    
    for(i=0;i<num;++i)
        cout<<array[i]<<" ";
 
    return 0;
}

Output:

Program to Implement Shell Sort in CPP (C plus plus)

Program to Implement Shell Sort in CPP (C plus plus)

 

Fazal Rehman Shamil Click Here to Know More
Instructor, Researcher, Blogger, SEO Expert, Poet and Publisher of International Journal Of Software, Technology & Science ISSN : 2616 - 5325
Dear Professors and Resarchers!You are welome to Cite these tutorials in your research or slides etc. Please don't forget to mention the reference of website. Copy Paste of text is strcitly forbidden. Images can be reuse because images are protected with watermark.

Leave a Reply

Your email address will not be published. Required fields are marked *