Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




Program to perform INSERTION SORT in C++

Download Attachment

/***********************************/
/*PROGRAM TO PREFORM INSERTION SORT*/
/***********************************/

#include < stdio.h>
#include < conio.h>

#define INF -999

void main()
{
    int a[10],n,i,j,temp;

    clrscr();

    a[0]=INF;
    printf("Enter the size of array: ");
    scanf( "%d",&n);
    printf("\nEnter the elements of array:\n");
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=2;i<=n;i++)
    {
        temp=a[i];
        j=i-1;
        while(temp        {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=temp;
    }

    printf("\nAfter sorting the elements of array are:\n");
    for(i=1;i<=n;i++)
    {
        printf("%d ",a[i]);
    }
    getch();
}

Share this article   |    Print    |    Article read by 2506 times
Author:
Rohit kakria
I am software developer
Related Articles:
Related Interview Questions: No related interview question