添加排序算法工具类
This commit is contained in:
parent
5dbf6b9170
commit
881d62b274
31
src_app_fresh/com/base/util/SortUtil.java
Normal file
31
src_app_fresh/com/base/util/SortUtil.java
Normal file
@ -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 + " ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user