static void shellsort(int a[], int n) { for (int gap = n / 2; gap >= 1; gap /= 2) { for (int i = gap; i < n; i++) { if (a[i] < a[i - gap]) { int temp = a[i]; int k = i - gap; while (k >= 0 && a[k] > temp) { a[k + gap] = a[k]; k -= gap; } a[k + gap] = temp; } } } }
原文:http://blog.csdn.net/hackcoder/article/details/25193445