JAVA之希尔排序


public class xier {
public static void main(String[] args) {
int[] A = new int[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
A = xier.shellSort(A, 10);
for (int i = 0; i < 10; i++) {
System.out.print(A[i] + " ");
}
}

public static int[] shellSort(int[] A, int n) {
int gap;// 步长
for (gap = n / 2; gap > 0; gap /= 2) {
for (int i = 0; i < gap; i++) {
// 这里开始插入排序
for (int j = i + gap; j < n; j += gap) {
int temp = A[j];
int k;
for (k = j - gap; k >= 0 && A[k] > temp; k -= gap)
A[k + gap] = A[k];
A[k + gap] = temp;
}
}
}
return A;
}
}


你可能感兴趣的:(C语言算法)