码迷,mamicode.com
首页 > 编程语言 > 详细

插入排序

时间:2016-09-15 00:49:02      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!