- /**
- * 冒泡排序
- *
- * @version 1.0
- * @date 2023/09/01 15:23:58
- */
- public class Bubble {
-
- /**
- * 升序冒泡排序
- *
- * @param a 待排序的数组
- * @date 2023/9/1 15:29:10
- */
- public static void sortAes(int[] a) {
- for (int i = a.length - 1; i > 0; i--) {
- for (int j = 0; j < i; j++) {
- if (a[j] > a[j+1]) {
- int temp = a[j];
- a[j] = a[j+1];
- a[j+1] = temp;
- }
- }
- }
- }
-
-
- /**
- * 降序冒泡排序
- *
- * @param a 待排序的数组
- * @date 2023/9/1 15:29:10
- */
- public static void sortDesc(int[] a) {
- for (int i = a.length - 1; i > 0; i--) {
- for (int j = 0; j < i; j++) {
- if (a[j] < a[j+1]) {
- int temp = a[j];
- a[j] = a[j+1];
- a[j+1] = temp;
- }
- }
- }
- }
-
-
- }
- public class BubbleTest {
- public static void main(String[] args) {
- int[] array = {56, 88, 23, 99, 12, 34, -15, -45, 78, 67, 32};
- //升序排列
- //Bubble.sortAes(array);
- //降序排列
- Bubble.sortDesc(array);
- System.out.println(Arrays.toString(array));
- }
- }