Sunday 16 December 2012

c program | Sorting of given number | implementation of Insertion sort


Logic and examples to sort given number in list.
In this article we will get idea about to sort number .
user will enter the number in any order like 4,5,3,67,8, etc..
and when we include in program it will get output like 3,4,5,8,67.
before to sort given number all the entered number will save in list .
then after it will sort by ascending order like small to bigger number and will show in ordered .
this program we call as Program for implementation of Insertion sort also.

#include<stdio.h>// header file
#include<conio.h>
#define max 20

void main() // start of main
{
int i,j,n,k,t,temp,a[max];//intializing variable and temp memory
clrscr();
printf("\How many no. you want to insert into list:- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter %d no:- ",i+1);
scanf("%d",&a[i]);
}
printf("\nUnsorted list is:-\n");// will display unsorted list
for(i=0;i<n;i++)
printf("\n%d",a[i]);
for(i=1;i<n;i++)
{
for(j=0;j<i;j++)
{
if(a[i]<a[j])// cheking first value is less than next one
{
temp=a[j];
a[j]=a[i];
for(k=i;k>j;k--)
a[k]=a[k-1];
a[k+1]=temp;
}
}
}
printf("\n\nSorted list is:-\n");// will print sorted order in a list
for(i=0;i<n;i++)
printf("\n%d",a[i]);
getch();
}


Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: