diff --git a/src_app_fresh/com/base/util/SortUtil.java b/src_app_fresh/com/base/util/SortUtil.java new file mode 100644 index 000000000..5164f4ebf --- /dev/null +++ b/src_app_fresh/com/base/util/SortUtil.java @@ -0,0 +1,31 @@ +package com.base.util; + +public class SortUtil { + + /** + * 冒泡算法 int[] + * + * @param args + */ + public static void bubbleSort(int[] arr) { + System.out.println("排序前数组为:"); + for (int num : arr) { + System.out.println(num + " "); + } + for (int i = 0; i < arr.length - 1; i++) { + for (int j = 0; j < arr.length - 1 - i; j++) { + if (arr[j] > arr[j + 1]) { + int temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + } + } + } + System.out.println("排序后的数组为:"); + for (int num : arr) { + System.out.println(num + " "); + } + } + + +}