1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
public static int[] lenRandomValueRandom(int maxLen, int maxValue) { int len = (int) (Math.random() * maxLen); int[] ans = new int[len]; for (int i = 0; i < len; i++) { ans[i] = (int) (Math.random() * maxValue); } return ans; }
public static boolean isEqual(int[] arr1, int[] arr2) { int len = arr1.length; for (int i = 0; i < len; i++) { if (arr1[i] != arr2[i]) { return false; } } return true; }
public static int[] copyArray(int[] arr) { int[] ans = new int[arr.length]; int len = arr.length; for (int i = 0; i < len; i++) { ans[i] = arr[i]; } return ans; }
public static void main(String[] args) { int maxLen = 1000; int maxValue = 1000; int testTime = 1000000;
for (int i = 0; i < testTime; i++) { int[] arr1 = lenRandomValueRandom(maxLen, maxValue); int[] arr2 = copyArray(arr1); ArraySort.bubbleSort(arr1); ArraySort.insertSort(arr2); if (!isEqual(arr1, arr2)) { ArraySort.printArray(arr1); ArraySort.printArray(arr2); } } System.out.println("nothing happen!"); }
|