Like us on Facebook and stand a chance to win pen drives!

Insertion Sort Algorithm




#include<stdio.h>
int main()
{
  int array[10];
   int i;

    for(i=1;i<11;i++)
     {
        printf("Enter N0 :",i);
        scanf("%d", &array[i]);
     }
   int j,key,y;
   for(j=2;j<11;j++)
    {
       y=1;
        while(array[j]>array[y])
               y=y+1;
          key=array[j];
       int k;
       for(k=0;k<=(j-y-1);k++)
        {
            array[j-k]=array[j-k-1];
        }
   array[y]=key;
    }
  int m;
  for(m=1;m<11;m++)
   {
      printf("%d\n",array[m]);
   }
}






Comment with Facebook


Copyright © 2012 SLIIT Helper.