import cn.idestiny.util.GeneratedArray; /** * 插入排序算法实现 */ public class InsertionSort { public static void main(String[] args) { //随机生成指定长度数组 int[] randomarr = GeneratedArray.randomGeneratedArray(50, 60, 10000); //打印为排序的数组 GeneratedArray.printArray(randomarr); long start = System.currentTimeMillis(); for (int i = 1;i<randomarr.length;i++){ int key = randomarr[i]; int j = i-1; while(j>=0&&randomarr[j]<key){ randomarr[j+1] = randomarr[j]; j--; } randomarr[j+1]=key; } System.out.println(System.currentTimeMillis()-start); //打印排序好的数组 GeneratedArray.printArray(randomarr); } }