{
int inner, outer;
int temp;
//Knuth’s recursion for initial interval sequence
int h = 1;
while(h<=aSize/3)
h = h*3 + 1;
//At each gap interval step
while(h>0)
{
//Arrange each subset with insertion sorting
//Start comparing the second element of the
//subset to the first one
for(outer=h;outer
//Make a copy of the first element
//not yet sorted
temp = data[outer];
inner = outer;
//And compare to all elements of the same
//subset that have been sorted already
while(inner > h-1 && data[inner – h] >= temp)
{
//move bigger values forward h steps
data[inner] = data[inner - h];
inner -= h;
}
//and insert the not sorted element on its
place
data[inner] = temp;
}
//Next interval in the sequence
h = (h-1)/3;
}
}
0 comments:
Post a Comment