排序算法之插入排序
原理:
1 package com.yhq.buildspringmvc.data; 2 3 import java.util.Arrays; 4 5 /** 6 * 排序算法之插入排序 7 * 8 * @author YuHaiQing 9 * @date 2018-04-23 14:16 10 */ 11 public class InsertSort { 12 13 public static void main(String[] args){ 14 15 int[] arr = {12,52,69,84,15,32,64,32,83}; 16 17 for(int i = 1; i < arr.length; i++){ 18 19 int variable = arr[i]; 20 int index = i; 21 22 while (index > 0 && arr[index - 1] >= variable){ 23 arr[index] = arr[index - 1]; 24 --index; 25 } 26 arr[index] = variable; 27 } 28 System.out.println(Arrays.toString(arr)); 29 } 30 }