From 3547fd1db9274507a1a5930dab447f01c812930c Mon Sep 17 00:00:00 2001 From: Draconis777 <14287216+draconis777@user.noreply.gitee.com> Date: Thu, 11 Apr 2024 01:15:21 +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/DRACONIS/15846543.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 codes/DRACONIS/15846543.java diff --git a/codes/DRACONIS/15846543.java b/codes/DRACONIS/15846543.java new file mode 100644 index 00000000..4f071a45 --- /dev/null +++ b/codes/DRACONIS/15846543.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]) { + int temp = a[j]; + a[j] = a[j + 1]; + a[j + 1] = temp; + } + } + } +} //end -- Gitee