From 9663d9b81fb59a1a3e1ee501b5598daf7e2d0318 Mon Sep 17 00:00:00 2001 From: Greyl_hl <14262416+greyl_hl@user.noreply.gitee.com> Date: Fri, 5 Apr 2024 13:57:21 +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/Greyl_hl/15777619.java | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 codes/Greyl_hl/15777619.java diff --git a/codes/Greyl_hl/15777619.java b/codes/Greyl_hl/15777619.java new file mode 100644 index 000000000..05e8d2a14 --- /dev/null +++ b/codes/Greyl_hl/15777619.java @@ -0,0 +1,37 @@ +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]) { + + // 如果前一个元素大于后一个元素,则交换他们的位置 + + int temp = a[j]; + + a[j] = a[j + 1]; + + a[j + 1] = temp; + + } + + } + + } + + } //end -- Gitee From b04c7bc36ef2a99e38cdf3eeffc627d4f261983a Mon Sep 17 00:00:00 2001 From: Greyl_hl <14262416+greyl_hl@user.noreply.gitee.com> Date: Fri, 5 Apr 2024 14:28:46 +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/Greyl_hl/15777619.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/codes/Greyl_hl/15777619.java b/codes/Greyl_hl/15777619.java index 05e8d2a14..9da8ded19 100644 --- a/codes/Greyl_hl/15777619.java +++ b/codes/Greyl_hl/15777619.java @@ -1,5 +1,3 @@ -java -复制代码 /** * 冒泡排序函数 -- Gitee