C/C++/Java
1 gap = X;
2 do
3 { ok = 1;
4 for (i = 1; i<= N – gap; i++)
5 if (A[i] > A[i+gap])
6 { temp = A[i];
7 A[i] = A[i+gap];
8 A[i+gap] = temp;
9 ok = 0;
10 }
11 if (gap/2 > 1) gap=gap/2; else gap=1;
12 } while (ok == 0);