Insertion Sort(C++)

 


#include <conio.h>
#include <stdio.h>
#include <iostream>
int main()
{
    int arr[5]={3,5,2,99,1};
    int temp,k,i,j;int key;
    for(j=1;j<5;j++)
{
        key=arr[j];
for(i=j-1;(i>=0)&&(arr[i]<key);i--)
{temp=arr[i+1];
            arr[i+1]=arr[i];
        arr[i]=temp;
    }
   key =arr[i+1];
}
    for(k=0;k<5;k++)
 
{
    printf("%d",arr[k]);
}
    getch();
}
Posted by lol ik

Comments

Popular Posts