Can anyone please tell with full explaination code for insertion sort using arrays? I am not able to understand it through the website
Have a look at https://www.codesdope.com/blog/article/sorting-an-array-using-insertion-sort-in-c/
#include <stdio.h>
#include <math.h>
int main()
{
int a[] = {16, 19, 11, 15, 10, 12, 14};
int i,j;
for(i=0;i<7;i++)
{
for(j=i; j>0; j--)
{
//not in order
if(a[j-1] > a[j])
{
//swapping
int temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;
}
//in order
else
{
break;
}
}
}
for(i=0;i<7;i++)
printf("%d\n",a[i]);
return 0;
}