少年阿宾

那些青春的岁月

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
package com.abin.lee.algorithm.insert;
import java.util.Arrays;
public class InsertSort {
public static void main(String[] args) {
int[] input = {6,1,4,2,5,8,3,7,9,0};
input = InsertSort.sort(input);
System.out.println(Arrays.toString(input));
}
public static int[] sort(int[] input){
int temp = 0;
for(int i=0;i<input.length;i++){
temp = input[i];
int j=i-1;
for(;j>=0&&temp<input[j];j--){
input[j+1] = input[j];
}
input[j+1] = temp;
}
return input;
}
}
posted on 2014-10-19 01:20 abin 阅读(362) 评论(0)  编辑  收藏 所属分类: algorithm

只有注册用户登录后才能发表评论。


网站导航: