Insertion Sort


       Write a program to perform insertion sort.

       /* Prg to perform insertion short. */

   /* In this insertion sort the element will be sort in ascending order. */

   #include<stdio.h>

   #include<conio.h>

   void is(int[], int);

   main()

   {

/*here ne means number of elemnts in array.*/

/*here a means array.*/

/*here bs means insertion sort. */

int a[50],ne,i;

printf ("Enter how many elements you wants to perform insertion sort = ");

scanf("%d",&ne);

printf ("Enter the elements in array :-\n");

for (i=0;i<ne;i++)

{

    scanf ("%d",&a[i]);

}

is(a,ne);

printf ("Elements after sort :-\n");

for (i=0;i<ne;i++)

{

    printf("%d\t",a[i]);

}

    }

    void is (int a[], int ne)

    {

  int pass, element, data;

  for(pass=1; pass<ne; pass++) // to select element.

  {

      data=a[pass];

      for(element=pass-1;element>=0 && data <= a[element];element--) // comparision with data to perform shifting

    {

a[element + 1] = a[element];

    }

a[element+1]=data;

}

    }