public class Paixu { public static void main(String[] args) { int[] arr = new int[]{9, 8, 7, 6, 5, 4, 3, 2, 1}; int[] arrs = ChaRu(arr); System.out.println(Arrays.toString(arrs)); } public static int[] ChaRu(int[] arr) { for (int i = 1; i < arr.length; i++) { int curr = arr[i]; int temp = i - 1; while (temp >= 0 && curr < arr[temp]) { arr[temp + 1] = arr[temp]; temp--; } arr[temp + 1] = curr; } return arr; }}
插入排序(Java代码实现)
时间:2023-08-05
相关推荐