Wednesday, September 17, 2008

INSERTION SORT

INSERTION SORT

void main()
{
int i,j,s,temp,a[20];
clrscr();
printf("\nEnter size of the array: ");
scanf("%d",&s);
printf("\nEnter %d elements in to the array:",s);
for(i=0;i
scanf("%d",&a[i]);
for(i=1;i
{
temp=a[i];
j=i-1;
while((temp=0))
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=temp;
}
printf("\nAfter sorting the elements are: ");
for(i=0;i
printf(" %d",a[i]);
getch();
}

No comments:

Post a Comment

Thanks to given comments.......

My Blog List