Say I have a list of numbers:
89 12 18 4 6
and I want to implement an insertion sort and have it print every step of the sort onto the screen:
Sort 1. 12 89 18 4 6
Sort 2. 4 12 89 18 6
Sort 3. 4 6 12 89 18
Sort 4. 4 6 12 18 89
here's the code that I have so far, I'm confused as to where to insert the printf inside the loop.
void insertion_sort(FILE *fp, int ar[15])
{
int i, j, temp;
for (i = 0; i < 15; i++)
printf("%d\n", ar[i]);
for(i = 0; i < 15; i++) {
temp = ar[i];
for(j = i - 1; j >= 0 && ar[j] > temp; j--)
ar[j + 1] = ar[j];
ar[j + 1] = temp;
}