DS1(SORTING)(PART 3) || Insertion sort using C-Language - NESTED CODE || TECH FLOAT

Breaking

Post Top Ad

Post Top Ad

Friday, 24 August 2012

DS1(SORTING)(PART 3) || Insertion sort using C-Language


  1.  INSERTION SORT

Code for Insertion sort………

#include<stdio.h>
int main()
{
    int a[100],i,n,temp,k,j;
    printf("Enter how many noumbers ??\n");
    scanf("%d",&n);
    printf("Put the numbers are in unsorted oriented\n");
    for(i=0;i<n;i++)
    {
                    scanf("%d",&a[i]);
    }
     printf("The Inputed array::\n");
    for(i=0;i<n;i++)
    {
                printf("%d ",a[i]);
    }
//##############################################################################
//sorting process
for(k=0;k<n;k++)
{
                temp=a[k];
                j=k-1;
                while((temp<a[j]) && (j>=0))
                {
                                  a[j+1]=a[j];
                                  j=j-1;
                }
                a[j+1]=temp;
}
//##############################################################################
//output
printf("\n\nThe Sorted array is::\n");
for(i=0;i<n;i++)
{
                printf("%d ",a[i]);
}
getch();
return 0;
}

Output ::





No comments:

Post a Comment

Post Bottom Ad