From 614d954e4c5afa790fcb53f91ea5827fad62ba79 Mon Sep 17 00:00:00 2001 From: sypp <14262364+sypp2024@user.noreply.gitee.com> Date: Fri, 5 Apr 2024 13:19:50 +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/sypp2024/15777497.java | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 codes/sypp2024/15777497.java diff --git a/codes/sypp2024/15777497.java b/codes/sypp2024/15777497.java new file mode 100644 index 000000000..ca4d077da --- /dev/null +++ b/codes/sypp2024/15777497.java @@ -0,0 +1,36 @@ +java + /** + + * 冒泡排序函数 + + * + + * @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]) { + + // 交换 a[j] 和 a[j + 1] + + int temp = a[j]; + + a[j] = a[j + 1]; + + a[j + 1] = temp; + + } + + } + + } + + } //end -- Gitee From f98b074b6fb58f996fcf4993a564be0ef8edf5b1 Mon Sep 17 00:00:00 2001 From: sypp <14262364+sypp2024@user.noreply.gitee.com> Date: Fri, 5 Apr 2024 14:38:09 +0800 Subject: [PATCH 2/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/sypp2024/15777741.java | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 codes/sypp2024/15777741.java diff --git a/codes/sypp2024/15777741.java b/codes/sypp2024/15777741.java new file mode 100644 index 000000000..7df7a9801 --- /dev/null +++ b/codes/sypp2024/15777741.java @@ -0,0 +1,37 @@ +java +复制代码 + /** + + * 冒泡排序函数(更通用的版本) + + * 通过相邻元素之间的比较和交换,使得每一轮循环后最大(或最小)的元素能够“冒”到数组的一端 + + * @param a 待排序的数组 + + */ + + public static void bubbleSort(int[] a){ + + int n = a.length; + + for (int i = 0; i < n - 1; i++) { + + for (int j = 0; j < n - 1 - i; 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