1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
const int harr[] =
{
0, /*terminal condition for sort */
1, 3,7,
10,
53,
105,
542,
1047,
6239,
16256,
56720,
134096,
579823,
1000021,
5430201,
999999999 /*terminal condition for find index */
};
void ssort(stype *list , const int size);
void ssort(stype *list , const int size)
{
int i;
int j, dx = 1;
while(size > harr[dx])
{
dx++; /*get index in sequence, +1 */
}
while(--dx)
{
const int hdx = harr[dx]; //this guy is important!
for(i = hdx; i < size; i++)
{
const stype temp = list[i];
for(j = i; (j >= hdx) && (list[j-hdx] > temp); j -= hdx)
{
list[j] = list[j-hdx];
}
list[j] = temp;
}
}
}
|