Program for inserstion sort using while loop

//program for inserstion sort using while loop;

#include "iostream.h"
#include "conio.h"
class anand
{
int a[10],n,i,j,temp;
public:
void getdata();
void showdata();
void calculate();
};
void anand::getdata()
{
cout<<"ENTER THE SIZE OF ARRAY:";
cin>>n;

for(i=0;i<=n-1;i++)
{
cout<<"\n\nENTER EL:"; cin>>a[i];

}
}
void anand::showdata()
{
cout<<"\nAFTER SORTING THE SERIES IS:"<<" \n\n";

for(i=0;i<=n-1;i++)
cout<<" "<
=0) //inner loop
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
j--;
}

else
break;
} // end of inner while loop
I++;
}
}

void main()
{
clrscr();
anand x;
x.getdata();
x.calculate();
x.showdata();
getch();
}

No comments:

Post a Comment