代码
package lvyy_test;
import java.util.Arrays;
import java.util.List;
public class XiEr {
public static void main(String[] args) {
List<Integer> nums = Arrays.asList(10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
int size = nums.size();
for (int step = size / 2; step >= 1; step /= 2) {
for (int start = step; start < size; start++) {
int temp = nums.get(start);
int compartIndex = start - step;
while (compartIndex >= 0 && nums.get(compartIndex) > temp) {
nums.set(compartIndex + step, nums.get(compartIndex));
compartIndex -= step;
}
nums.set(compartIndex + step, temp);
System.out.println(nums);
}
System.out.println();
}
}
}
控制层结果