Insertion Sort

#include<stdio.h>
void main()
{
    int r,i,temp,j,min;
    int a[10];

    printf("Enter the size of array\n");
    scanf("%d",&r);

    printf("\nEnter the Array  values\n");
    for(i=0;i<r;i++)
        scanf("%d",&a[i]);
   for(i=0;i<r-1;i++)
    {
        for(j=i;j>=0;j--)
            if(a[j+1]<a[j])
            {
             temp=a[j+1];
             a[j+1]=a[j];
             a[j]=temp;
            }
             printf("\nAfter %d Iteration",i+1);
               for(j=0;j<r;j++)
                printf("\t%d",a[j]);
    }
printf("\nSorted order\t");
    for(i=0;i<r;i++)
        printf("\t%d",a[i]);
}

No comments:

Post a Comment

Thank you for using this blog.