Today I studied the following shell sort code:

I follow it all except for one part. In the innermost loop, the final loop expression:Code:void shellsort(int v[], int n) { int gap, i, j, temp; for (gap = n/2; gap > 0; gap /= 2) for(i = gap; i < n; i++) for (j=i-gap; j>= 0 && v[j]>v[j + gap]; j-=gap){ temp = v[j]; v[j] = v[j + gap]; v[j+gap] = temp; } }

What is the point of this? Can you not just write this loop as:Code:j -= gap

and have the second loop control the amount of times elements are compared?Code:for (j=i-gap; j>= 0 && v[j]>v[j + gap];)

Cheers

BIOS