Insertion Sort
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a[]={1,2,6,8,9,4,5,7,0,3,2};
int temp;
for(int i=0;i<11;i++)
{
for( int j=0;j<11;j++ )
{
if( a[j+1]<a[j] )
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"After Sorting\n";
for(int i=0;i<11;i++)
{
cout<<' '<<a[i]<<' ';
}
getch();
return (0);
}
Sample Output:
Comments
Post a Comment
Thanks for the comment and don't forget to subscribe.