Insert sorting in Java and insert sorting in java
Package com; public class Paixu {static boolean flag = true; public static void main (String [] args) {// TODO Auto-generated method stub int [] a = random (50000); long l1 = System. currentTimeMillis (); insertion_Sort (a); long l2 = System. currentTimeMillis (); System. out. println ("insert sort:" + (l2-l1); check (a);} // insert sort private static int [] insertion_Sort (int []) {/* for (int I = 1; I <. length; I ++) {int temp = a [I]; for (int j = I-1; j> = 0; j --) {if (a [j]> temp) {a [j + 1] = a [j]; if (j = 0) {a [0] = temp ;}} else {a [j + 1] = temp; break ;}}* // optimized insertion Sorting Algorithm for (int I = 1; I <. length; I ++) {int temp = a [I]; int j; for (j = I-1; j> = 0; j --) {if (a [j]> temp) {a [j + 1] = a [j];} else {break;} a [j + 1] = temp ;} /* int I, j; int n =. length; for (I = 1; I <n; I ++) {j = I; int target = a [I]; while (j> 0 & target <a [J-1]) {a [j] = a [J-1]; j --;} a [j] = target ;} */System. out. println ("***********************"); return ;} public static int [] random (int num) {long start = System. currentTimeMillis (); int [] a; a = new int [num]; for (int I = 0; I <num; I ++) {int rand = (int) math. round (Math. random () * num * 100); a [I] = rand;} long end = System. currentTimeMillis (); System. out. println ("generate" + num + "random number time =>" + (end-start) + "millisecond"); return ;} private static boolean check (int [] a) {for (int I = 0; I <. length-1; I ++) {if (a [I + 1] <a [I]) {flag = false ;}} System. out. println (flag); return flag ;}}