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

插入排序(数据是局部有序的)

时间:2016-06-14 19:34:52      阅读:341      评论:0      收藏:0      [点我收藏+]

标签:

在数据中选择一个作为标识,如果左侧的比标识数据大,那么将标识的位置与标识左侧数据进行调换,否则保持不变。
public int[] initData(){
int[] data = {2,3,4,8,9,7,5,6,10,1};
return data;
}

public static void order(int[] data){
int in,out,temp;
for(out = 1 ; out<data.length;out ++){
temp = data[out];
in = out;
while(in > 0 && data[in - 1] >= temp){
data[in] = data[in - 1];
-- in;
}
data[in] = temp;
}

for(int j : data){
System.out.print(j);
}
}

public static void main(String[] args) {
order(new Insert().initData());
}

插入排序(数据是局部有序的)

标签:

原文地址:http://www.cnblogs.com/zhuzhiq/p/5585002.html

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