From 14aefe3b6f8cc8de42033b0e72188e6141294110 Mon Sep 17 00:00:00 2001 From: linsity <14266884+linsity@user.noreply.gitee.com> Date: Sat, 6 Apr 2024 22:24:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes/Linsity/Linsity.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 codes/Linsity/Linsity.java diff --git a/codes/Linsity/Linsity.java b/codes/Linsity/Linsity.java new file mode 100644 index 00000000..34f5111e --- /dev/null +++ b/codes/Linsity/Linsity.java @@ -0,0 +1,32 @@ +[200~/** + * 冒泡排序函数 + * * 通过相邻元素两两比较和交换,使得每一轮迭代后最大(或最小)的元素被交换到序列末尾 + * * @param a 待排序的数组 + * * @param n 待排序的数组长度 + * */ +public static void bubbleSort(int[] a, int n) { + // 遍历整个数组 + // for (int i = 0; i < n - 1; i++) { + // // 设置一个标志位,表示本趟是否发生了交换 + // boolean swapped = false; + // + // // 从数组的第一个元素开始到倒数第二个元素 + // 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; + // + // // 发生了交换,设置标志位为true + // swapped = true; + // } + // } + // + // // 如果本趟遍历没有发生交换,则数组已经有序,可以结束排序 + // if (!swapped) { + // break; + // } + // } + // } // end -- Gitee From efddcc71900708cf6ed4c3adfc4de8135956df36 Mon Sep 17 00:00:00 2001 From: linsity <14266884+linsity@user.noreply.gitee.com> Date: Sat, 6 Apr 2024 14:40:45 +0000 Subject: [PATCH 2/2] rename codes/Linsity/Linsity.java to codes/Linsity/linsity.java. Signed-off-by: linsity <14266884+linsity@user.noreply.gitee.com> --- codes/Linsity/{Linsity.java => linsity.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename codes/Linsity/{Linsity.java => linsity.java} (100%) diff --git a/codes/Linsity/Linsity.java b/codes/Linsity/linsity.java similarity index 100% rename from codes/Linsity/Linsity.java rename to codes/Linsity/linsity.java -- Gitee