import java.util.Arrays;
public class Test {
public static void main(String[] args) {
int[] array = { 80, 70, 50, 30, 99, 1 };
Test.insertSort(array);
System.out.println(Arrays.toString(array));
}
private static int[] insertSort(int[] array) {
if (array == null || array.length < 2) {
return array;
}
for (int i = 1; i < array.length; i++) {
for (int j = i; j > 0; j--) {
if (array[j] < array[j - 1]) {
int temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
} else {
break;
}
}
}
return array;
}
}
插入排序(java实现)
最新推荐文章于 2022-03-27 15:17:59 发布