1. 程式人生 > >Shell排序法-Java實現

Shell排序法-Java實現

public static void shellSort(int[] a) {
		int i, j, h;
		int r, temp;
		int x = 0;

		for (r = a.length; r >= 1; r /= 2)
			for (i = r; i < a.length; i++) {
				temp = a[i];
				j = i - r;
				while (j >= 0 && temp < a[j]) {
					a[j + r] = a[j];
					j -= r;
				}
				a[j + r] = temp;
			}
	}