插入排序算法

来源:互联网 发布:是焉得为大丈夫乎的得 编辑:程序博客网 时间:2024/06/15 09:48
package com.test;


/**
 * @ClassName: InsertSort.java
 * @Description: 插入排序算法
 * @author Bert
 * 2014-4-3 下午9:00:03
 */
public class InsertSort {


public static void main(String[] args) {

Integer[] num = {8,9,5,6,7,5,2,5,9,14,2};

if(num == null ){

return;

}


int temp ;
for (int i = 0; i < num.length; i++) {
for (int j = i + 1; (j > 0) && (num[j] < num[j-1]); j --) {
temp = num[j];
num[j] = num[j-1];
num[j-1] = temp;
}
}
for (int i : num) {
System.out.println(i);
}
}
}
0 0
原创粉丝点击