#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void main()
{
int A[50],n,i,j,Temp;
clrscr();
cout<<"\nINSERTION SORT ";
cout<<"\n\nHOW MANY NUMBERS YOU HAVE.: ";
cin>>n;
cout<<"\nENTER THE ELEMENTS OF THE ARRAY...:\n";
for(i=1;i<=n;i++)
{
cin>>A[i];
}
for(i=2; i<=n; i++)
{
Temp = A[i];
j = i-1;
while(Temp<A[j] && j>=1)
{
A[j+1] = A[j];
j = j-1;
}
A[j+1] = Temp;
}
cout<<"\n\nSORTED LIST IN ASCENDING ORDER.:\n";
for(i=1; i<=n; i++)
cout<<A[i]<<"\n";
getch();
}
#include<conio.h>
#include<iostream.h>
void main()
{
int A[50],n,i,j,Temp;
clrscr();
cout<<"\nINSERTION SORT ";
cout<<"\n\nHOW MANY NUMBERS YOU HAVE.: ";
cin>>n;
cout<<"\nENTER THE ELEMENTS OF THE ARRAY...:\n";
for(i=1;i<=n;i++)
{
cin>>A[i];
}
for(i=2; i<=n; i++)
{
Temp = A[i];
j = i-1;
while(Temp<A[j] && j>=1)
{
A[j+1] = A[j];
j = j-1;
}
A[j+1] = Temp;
}
cout<<"\n\nSORTED LIST IN ASCENDING ORDER.:\n";
for(i=1; i<=n; i++)
cout<<A[i]<<"\n";
getch();
}