插入排序 发表于 2019-10-12 | 分类于 算法 , 八大排序 字数统计: | 阅读时长 ≈ 插入排序1234567891011121314151617181920212223242526272829303132package cn.llnn.sort;import java.util.Arrays;/** * 插入排序 * * @author llnn * @create 2019-09-26 18:01 **/public class InsertSort { public static void main(String[] args) { int[] a = {51, 46, 20, 18, 65, 97, 82, 30, 77, 50}; System.out.println("待排序:" + Arrays.toString(a)); insertSort(a); System.out.println("结果:" + Arrays.toString(a)); } private static void insertSort(int[] a) { for (int i = 1; i < a.length; i++) { int temp = a[i]; int j = i; while (j > 0 && a[j - 1] > temp) { a[j] = a[j - 1]; j--; } a[j] = temp; } }}