希尔排序

mac2022-06-30  91

package com.dhcc.project; public class Demo4 { public static void main(String[] args) { int[] arr = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; for (int gap = 4; gap > 0; gap /= 2) { for (int i = gap; i < arr.length; i++) { for (int j = i; j > gap - 1; j -= gap) { if (arr[j] < arr[j - gap]) { int temp = arr[j]; arr[j] = arr[j - gap]; arr[j - gap] = temp; } } } } for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } }

希尔排序算法

最新回复(0)