From 0eecd0b83b6c0b94bb7ef8ff3f27d159e0c4c6f1 Mon Sep 17 00:00:00 2001 From: aaric-ai <> Date: Thu, 17 Sep 2026 10:23:20 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=20Hello.java=20=E9=87=8C=E9=9D=A2?= =?UTF-8?q?=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=86=92=E6=B3=A1=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hello.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Hello.java b/Hello.java index c19662a..e71cf8a 100644 --- a/Hello.java +++ b/Hello.java @@ -49,4 +49,30 @@ public class Hello return fibonacci; } + + /** + * 使用冒泡排序算法对整数数组进行升序排序 + * + * @param array 待排序的整数数组,如果为null或长度小于2则直接返回 + */ + public static void bubbleSort(int[] array) { + if (array == null || array.length < 2) { + return; + } + int n = array.length; + for (int i = 0; i < n - 1; i++) { + boolean swapped = false; + for (int j = 0; j < n - 1 - i; j++) { + if (array[j] > array[j + 1]) { + int temp = array[j]; + array[j] = array[j + 1]; + array[j + 1] = temp; + swapped = true; + } + } + if (!swapped) { + break; + } + } + } } \ No newline at end of file -- Gitee