Wednesday 22 August 2012

Unsorted list | Sorted list | implementation of Insertion Sort | output

/* Program for implementation of Insertion Sort */


#include<stdio.h>
#include<conio.h>
#define max 20

void main()
{
int i,j,n,k,t,temp,a[max];
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");
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])
{
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");
for(i=0;i<n;i++)
printf("\n%d",a[i]);
getch();
}

/*
Output:-

How many no. you want to insert into list:- 5

Enter 1 no:- 4
Enter 2 no:- 3
Enter 3 no:- 5
Enter 4 no:- 2
Enter 5 no:- 1

Unsorted list is:-

4
3
5
2
1

Sorted list is:-

1
2
3
4
5

*/
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: