Write a Program in c that implement insertion sort, to sort a given list of integers in ascending order
/* Write a Program in c that implement insertion sort, to sort a given list of integers in ascending order*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
int array[10],n,j,i,t;
printf(" enter no of array elements : \n");
scanf("%d",&n);
printf(" enter unsorted %d elements \n",n);
for(i=1;i<=n;i++)
{
scanf("%d",&array[i]);
}
for(i=1;i<=n;i++)
{
for(j=2;j<=n;j++)
{
if(array[j] < array[j-1])
{
t=array[j];
array[j]=array[j-1];
array[j-1]=t;
}
}
}
printf("SORTED ARRAY AFTER INSERTION SORT : \n " );
for(i=1;i<=n;i++)
{
printf("%d \n", array[i]);
}
getch();
}
Comments
Post a Comment