Sunteți pe pagina 1din 1

#include <iostream.

h>
#include<conio.h>
#define e 6
void insertion_sort(int x[],int length)
{
int k,i;
for(int j=1;j<length;j++)
{
k=x[j];
i=j-1;
while(x[i]>k && i>=0)
{
x[i+1]=x[i];
i--;
}
x[i+1]=k;
}
}
int main()
{
int a[e];
clrscr();
cout<<"\n\n\t\t\tInsertion Sort";
cout<<"\n\n\t\t\t**************";
cout<<"\n\nEnter six elements for sorting : ";
for(int i=0;i<e;i++)
{
cin>>a[i];
}
int x;
cout<<"\n\nNON SORTED LIST:"<<endl;
cout<<"\n\n****************";
for(x=0;x<e;x++)
{
cout<<a[x]<<endl;
}
insertion_sort(a,e);
cout<<endl<<"\n\nSORTED LIST"<<endl;
cout<<"\n\n***********";
for(x=0;x<e;x++)
{
cout<<a[x]<<endl;
}
getch();
return 0;
}