package cn.hcm;public class InsertSort { /** * 插入排序 * @param source * @return */ public static int[] insertSort(int[] source) { if(source == null) { return null; } if(source.length == 0 || source.length == 1) { return source; } for(int i=1; i=0; j--) { if(source[j+1] < source[j]) { int temp = source[j]; source[j] = source[j+1]; source[j+1] = temp; } else { break; } } } return source; } public static void main(String[] args) { int[] source = InsertSort.insertSort(new int[]{-67,-5,-2,4,6,55,1,3}); for(int i:source) { System.out.println(i); } } }