C++ program to implement Shell sort using class

#include<iostream.h>
#include<constream.h>
void read(int a[10],int n)
{
	cout<<"reading\n";
	for(int i=0;i<n;i++)
		cin>>a[i];
}
void display(int a[10],int n)
{
	for(int i=0;i<n;i++)
		cout<<a[i]<<"\t";
}
void shellsort(int a[10],int n)
{
	int gap=n/2;
	do
	{
		int swap;
		do
 
		{
			swap=0;
			for(int i=0;i<n-gap;i++)
				if(a[i]>a[i+gap])
				{
					int t=a[i];
					a[i]=a[i+gap];
					a[i+gap]=t;
					swap=1;
				}
		}
		while(swap);
	}
	while(gap=gap/2);
}
void main()
{
	int a[10];
	int n;
	clrscr();
	cout<<"enter n\n";
	cin>>n;
	read(a,n);
	cout<<"before sorting\n";
	display(a,n);
	shellsort(a,n);
	cout<<"\nafter sorting\n";
	display(a,n);
	getch();
}
Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

3 thoughts on “C++ program to implement Shell sort using class

Leave a Reply

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

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in