/**
* 希尔排序
*
* @param 注意
* :第三个for循环 k >= i && data[k - i] > temp,执行语句的顺序不可以调转
*
**/
public class ShellSort {
public static void main(String[] args) {
int temp, k;
int[] data = { 14, 52, 46, 78, 55, 22, 11, 44, 66, 99, 58, 91 };
for (int e = 0; e < data.length; e++) {
System.out.print(data[e] + " , ");
}
for (int i = data.length / 2; i > 0; i /= 2) {
for (int j = i; j < data.length; j++) {
temp = data[j];
for (k = j; k >= i && data[k - i] > temp; k = k - i)
data[k] = data[k - i];
data[k] = temp;
}
}
for (int e = 0; e < data.length; e++) {
System.out.print(data[e] + ",");
}
}
}
希尔排序
最新推荐文章于 2021-11-24 09:06:14 发布