package com.pra;
import java.util.Arrays;
/**
* @author evi
* @version 1.0.0
* @date 2019\8\15 22:57
*/
public class InsertSort {
public static void main(String[] args) {
int[] arr = {10, 2, 3, 56, 44};
insert_sort(arr, arr.length);
}
public static void insert_sort(int[] arr, int length) {
int temp;
for (int i = 0; i < arr.length - 1; i++) {
for (int j = i + 1; j > 0; j--) {
if (arr[j - 1] > arr[j]) {
temp = arr[j - 1];
arr[j - 1] = arr[j];
arr[j] = temp;
}else {
break;
}
}
}
System.out.println(Arrays.toString(arr));
}
}
插入排序
最新推荐文章于 2023-09-23 17:47:53 发布