public static void shellsort(int[] array) { int n = array.length; int d = n / 2; while(d > 0) { for(int i = d ;i < n;i++) { int j = i - d; while(j >= 0 && array[j] > array[j+d]) { int temp = array[j]; array[j] = array[j+d]; array[j+d] = temp; j = j - d ; } } d = d / 2; } } public static void main(String[] args) { int[] array = {100, 45, 17, 36, 21,17, 13, 7}; System.out.println("数组的长度:" + array.length); System.out.println("排序前的数组:"+Arrays.toString(array)); shellsort(array); System.out.println("排序后的数组:"+Arrays.toString(array)); for(int i : array) { System.out.print( i + " "); } }