#include<stdio.h>
#include<conio.h>
void main()
{
int i, j ,
n, temp,a[10];
clrscr();
printf(“Enter
the size of array\n”);
scanf(“%d”,&n);
printf(“Enter
%d elements \n”)
for(i=1;i<=n;i++)
{
scanf(%d”,
&a[i]);
}
for(i=1;i<=n;i++)
{
temp=a[i];
j=i-1;
while((temp<a[j]&&(j>=0))
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;
}
printf(“The
sorted array is\n”);
for(i=1;i<=n;i++)
{
printf(“%d”,a[i]);
}
getch();
}
Very informative article.Thank you author for posting this kind of article .
ReplyDeletehttp://www.wikitechy.com/view-article/insertion-sorting-
program-in-cpp-with-example-and-explanation
Both are really good,
Cheers,
Venkat