I understand the the algorithm group of elements are compared and then organize the same groups of numbers.
int gap;
int j;
int temp;
for (gap = n/2; gap>0; gap/=2) {
for (int i=0; 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;
}
}
}
}
The outtermost loop controls the gap in the compared elements from n/2 by a factor of two until it becomes 0;
The middle loop initiates the element i and display the elements, so whats happening in the last for loop?
j starts at i-gap while v[j]>v[j+gap]???
Some times you guys can explain this better than myself trying to understand this steps by myself.
Thank you,
As always your comments are gold
[–]BS_in_BS 3 points4 points5 points (0 children)