package sort; /** * Created by ozc on 2018/3/26. * * @author ozc * @version 1.0 */ public class ShellSort { public static void main(String[] args) { int[] arrays = {6, 4321, 432, 344, 55 }; shellSort(arrays); System.out.println("å ¬ä¼å·ï¼Java3y" + arrays); } /** * å¸å°æåº * * @param arrays */ public static void shellSort(int[] arrays) { //å¢éæ¯æ¬¡é½/2 for (int step = arrays.length / 2; step > 0; step /= 2) { //ä»å¢éé£ç»å¼å§è¿è¡æå ¥æåºï¼ç´è³å®æ¯ for (int i = step; i < arrays.length; i++) { int j = i; int temp = arrays[j]; // j - step å°±æ¯ä»£è¡¨ä¸å®åç»éå£çå ç´ while (j - step >= 0 && arrays[j - step] > temp) { arrays[j] = arrays[j - step]; j = j - step; } arrays[j] = temp; } } } }