插入排序 package com.gds.algorithms; /** * Created by yangzhanku on 2017/9/7. */ public class InsertionSortTest { public static void main(String[] args) { int[] arrayTest = {100, 9, 8, 78, 90, 10}; InsertionSort(arrayTest); } private static void InsertionSort(int[] arrayTest) { for (int j = 1; j < arrayTest.length; j++) { int key = arrayTest[j]; int i = j - 1; while (i >= 0 && arrayTest[i] > key) { arrayTest[i + 1] = arrayTest[i]; i--; } arrayTest[i + 1] = key; } for (int k : arrayTest) { System.out.print(k + " "); } } }