public static void shellSort(int[] arr) {int temp;//第1轮//因为第1轮排序,是将10个数据分成了5组for (int i = 5; i < arr.length; i++) {//遍历各组中所有的元素(共5组,每组有2个元素),步长5for (int j = i - 5; j >= 0; j -= 5) {//如果当前元素大于加上步长后的那个元素,说明需要交换if (arr[j] > arr[j + 5]) {temp = arr[j];arr[j] = arr[j + 5];arr[j + 5] = temp;}}System.out.printf("第1.%d趟排序结果:", i - 4);System.out.println(Arrays.toString(arr));}System.out.println("第1趟排序结果:");System.out.println(Arrays.toString(arr));//第2轮//第2轮排序,是将10个数据分成了 5/2=2组for (int i = 2; i < arr.length; i++) {//遍历各组中所有的元素(共2组,每组有5个元素),步长5for (int j = i - 2; j >= 0; j -= 2) {//如果当前元素大于加上步长后的那个元素,说明需要交换if (arr[j] > arr[j + 2]) {temp = arr[j];arr[j] = arr[j + 2];arr[j + 2] = temp;}}System.out.printf("第2.%d趟排序结果:", i - 1);System.out.println(Arrays.toString(arr));}System.out.println("第2趟排序结果:");System.out.println(Arrays.toString(arr));//第3轮//第3轮排序,是将10个数据分成了 5/2/2=1组for (int i = 1; i < arr.length; i++) {//遍历各组中所有的元素(共1组,每组有10个元素),步长10for (int j = i - 1; j >= 0; j -= 1) {//如果当前元素大于加上步长后的那个元素,说明需要交换if (arr[j] > arr[j + 1]) {temp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = temp;}}System.out.printf("第3.%d趟排序结果:", i);System.out.println(Arrays.toString(arr));}System.out.println("第3趟排序结果:");System.out.println(Arrays.toString(arr));}

