Techknow Study

Insertion sort program........

11:29:00 PM vikas 0 Comments Category :

Insertion sort is a technique to arrange the given no. in a order i.e. ascending order.It like inserting a card between three or four cards which comes in order if a right card insert in between them
Example:



PROGRAM

#include<conio.h>
#include<stdio.h>
#define max 5
void main()
{
int j,a[max],key,i,k;
clrscr();
printf("enter the array");
for(j=1;j<=max;j++)
{
scanf("%d",&a[j]);
}
for(i=1;i<=max;i++)
{
key=a[i];
k=i-1;
while(k>=0&&a[k]>key)
{
a[k+1]=a[k];
k--;
}
a[k+1]=key;
}
for(j=0;j<=max;j++)
{
printf("%d",a[j]);
}
getch();
}

RELATED POSTS

0 comments