From 161c97e77b44dd43e8a8d1fe43731de7b77167c3 Mon Sep 17 00:00:00 2001 From: sangjiexun <1009900122@qq.com> Date: Thu, 19 Dec 2024 01:34:18 +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/sangjiexun/19047594.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 codes/sangjiexun/19047594.java diff --git a/codes/sangjiexun/19047594.java b/codes/sangjiexun/19047594.java new file mode 100644 index 00000000..3f551b82 --- /dev/null +++ b/codes/sangjiexun/19047594.java @@ -0,0 +1,22 @@ +/** + * 冒泡排序函数 + * aa bb cc + * @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 - 1 - i; j++) { + // 如果相邻的元素顺序错误,交换它们 + if (a[j] > a[j + 1]) { + // 交换 + int temp = a[j]; + a[j] = a[j + 1]; + a[j + 1] = temp; + } + } + } +}//end + -- Gitee