2、冒泡排序
public class Sort { public static void main(String[] args) { int[] arr = RandomUtil.randomInts(100); System.out.println(JSONObject.toJSON(arr)); System.out.println(); quickSort(arr, 0, arr.length - 1); System.out.println(JSONObject.toJSON(arr)); } /** * 冒泡排序 * * @param arr */ private static void bubbleSort(int[] arr) { System.out.println(JSONObject.toJSON(arr)); System.out.println(); for (int i = 0; i < arr.length - 1; i++) { int temp = 0; for (int j = 0; j < arr.length - 1 - i; j++) { if (arr[j] > arr[j + 1]) { temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } System.out.println(JSONObject.toJSON(arr)); }