标签:
1 import org.junit.Test; 2 3 public class InsertSort { 4 5 //插入排序 6 public void insertSort(int[] array){ 7 8 for(int j = 1; j < array.length; ++j){ 9 int key = array[j]; 10 int i = j - 1; 11 while(i >= 0 && array[i] > key){ 12 array[i+1] = array[i]; 13 --i; 14 } 15 array[++i] = key; 16 } 17 } 18 19 20 @Test 21 public void test(){ 22 int[] array = {8,2,4,9,3,6}; 23 insertSort(array); 24 Array.print(array); 25 } 26 27 }
标签:
原文地址:http://www.cnblogs.com/wjf0/p/5873947.html