From 15f8df778f5586f5ae0d55191bff22d40a7db82d Mon Sep 17 00:00:00 2001 From: qierbao <14280780+qierbao@user.noreply.gitee.com> Date: Tue, 9 Apr 2024 23:27:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=92=E5=BA=8F=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes/qierbao/15831365.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 codes/qierbao/15831365.java diff --git a/codes/qierbao/15831365.java b/codes/qierbao/15831365.java new file mode 100644 index 00000000..2b6e96fe --- /dev/null +++ b/codes/qierbao/15831365.java @@ -0,0 +1,18 @@ +/** + * 冒泡排序函数 + * 使用冒泡排序算法对数组进行升序排序 + * @param a 待排序的数组 + * @param n 待排序的数组长度 + */ +public static void bubbleSort(int [] a, int n){ + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < n - i - 1; j++) { + if (a[j] > a[j + 1]) { + // 交换 a[j] 和 a[j + 1] + int temp = a[j]; + a[j] = a[j + 1]; + a[j + 1] = temp; + } + } + } +} //end -- Gitee