package sort; public class ShellSort { /** * 对æ°ç»åç»å¹¶å¯¹æ¯ä¸ªç»åç´æ¥æå ¥æåº, 宿å缩å°ç»çæ°é, éå¤æå ¥æåº, ç´å°ç¼©å°å°ä¸ä¸ªç» ç¬¬ä¸æ¬¡åç»æ°: section = n/2 == 0 ? n/2 : n/2+1, åç»è§å: * æ¯én/2æä¸ä¸ªæ°, å³[x]å[x+n/2]为ä¸ç» */ public void sort(int numbers[]) { int section = numbers.length / 2; int j; int temp; while (section >= 1) { for (int i = section; i < numbers.length; i++) { temp = numbers[i]; j = i - section; while (j >= 0 && numbers[j] > temp) { numbers[j + section] = numbers[j]; j = j - section; } numbers[j + section] = temp; } section /= 2; } System.out.print("æåºå: "); for (int x = 0; x < numbers.length; x++) { System.out.print(numbers[x] + " "); } } public static void main(String[] args) { int[] numbers = new int[] { 4, 3, 6, 2, 7, 1, 5, 8 }; ShellSort ins = new ShellSort(); ins.sort(numbers); } }