Write a Program To Sort the Elements Of an Array using “INSERTION SORT”.


Write a Program To Sort the Elements Of an Array using “INSERTION SORT”.

Write a Program To Sort the Elements Of an Array using “INSERTION SORT”.

SOURCE CODE:

#include
#include
void main()
{
clrscr();
int Temp,N,A[20],i,k;
printf("\nThis Program is Used To Sort the elements of Array Using INSERTION SORT");
printf("\nEnter The Number Of Elements To Be Inserted:");
scanf("%d",&N);
printf("\n\nEnter The Elements Of Array:");
for(i=1;i<=N;i++)
{
scanf("%d",&A[i]);
}
for(i=2;i<=N;i++)
{
Temp=A[i];
k=i-1;
while(k>=0&&Temp{
A[k+1]=A[k];
k=k-1;
}
A[k+1]=Temp;
}
printf("\nThe Sorted Array Is As:");
for(i=1;i<=N;i++)
{
printf("\n\n\t%d",A[i]);
}


getch();
}


OUTPUT


This program is used to sort the element of array using INSERTION SORT

Enter the number of elements to be inserted:5
Enter the elements of Array:77 33 11 21 89
The sorted Array is as:

11
21
33
77
89


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: