/* what is insertion sort*/
#include
#include
main()
{
int i,l[100],n,p,t,k;
clrscr();
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&l[i]);
}
l[0]=-0;
for(i=1;i<=n;i++)
{
p=i-1;
t=l[i];
while(t {
l[p+1]=l[p];
p--;
}
l[p+1]=t;
/* for( k=1;k<=n;k++)
{
printf("\t%d",l[k]);
}
printf("\n");*/
}
printf("Sorted list");
for(i=1;i<=n;i++)
{
printf("\t%d",l[i]);
}
getch();
}
#include
#include
main()
{
int i,l[100],n,p,t,k;
clrscr();
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&l[i]);
}
l[0]=-0;
for(i=1;i<=n;i++)
{
p=i-1;
t=l[i];
while(t
l[p+1]=l[p];
p--;
}
l[p+1]=t;
/* for( k=1;k<=n;k++)
{
printf("\t%d",l[k]);
}
printf("\n");*/
}
printf("Sorted list");
for(i=1;i<=n;i++)
{
printf("\t%d",l[i]);
}
getch();
}
This comment has been removed by the author.
ReplyDeleteThanks..
ReplyDeletegood work!!
ReplyDeleteniceeeeeeeeeee
ReplyDeleteCan you please display program with indentation??
ReplyDelete