//PROGRAM FOR INESERTION SORT;
#include
#include
class insert
{
int A[100],n,i,j,t,k;
public:
void get();
void show();
void sort();
};
void insert::get()
{
cout<<"ENTER THE SIZE OF ARRAY:";
cin>>n;
for(i=0;i<=n-1;i++)
{
cout<<"\n\nenter el:\t";
cin>>A[i];
}
}
void insert::show()
{
cout<<"\n\nthe series is:";
for(i=0;i<=n-1;i++)
cout< }
void insert::sort()
{
for(i=0;i<=n-2;i++) //for iteration's
{
if(A[i]>A[i+1])
{
t=A[i+1];
for(j=0;j<=i;j++)
{
if(t {
for(k=i+1;k>=j+1;k--)
{
A[k]=A[k-1];
}
A[j]=t;
break;
}
}
}
}
}
void main()
{
clrscr();
insert s;
s.get();
s.show();
cout<<"\n\nAFTER SORTING:";
s.sort();
s.show();
getch();
}
#include
#include
class insert
{
int A[100],n,i,j,t,k;
public:
void get();
void show();
void sort();
};
void insert::get()
{
cout<<"ENTER THE SIZE OF ARRAY:";
cin>>n;
for(i=0;i<=n-1;i++)
{
cout<<"\n\nenter el:\t";
cin>>A[i];
}
}
void insert::show()
{
cout<<"\n\nthe series is:";
for(i=0;i<=n-1;i++)
cout< }
void insert::sort()
{
for(i=0;i<=n-2;i++) //for iteration's
{
if(A[i]>A[i+1])
{
t=A[i+1];
for(j=0;j<=i;j++)
{
if(t {
for(k=i+1;k>=j+1;k--)
{
A[k]=A[k-1];
}
A[j]=t;
break;
}
}
}
}
}
void main()
{
clrscr();
insert s;
s.get();
s.show();
cout<<"\n\nAFTER SORTING:";
s.sort();
s.show();
getch();
}
No comments:
Post a Comment