From cbbc90a5a07967af5dec4a8c27a5d9431e1cdd6c Mon Sep 17 00:00:00 2001 From: piero_choi <1565984532@qq.com> Date: Tue, 15 Apr 2025 20:08:04 +0800 Subject: [PATCH 1/3] =?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/piero_choi/19955133.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 codes/piero_choi/19955133.java diff --git a/codes/piero_choi/19955133.java b/codes/piero_choi/19955133.java new file mode 100644 index 00000000..c04f3701 --- /dev/null +++ b/codes/piero_choi/19955133.java @@ -0,0 +1,12 @@ +/** + * 冒泡排序函数 + * aa bb cc + * @param a 待排序的数组 + * @param n 待排序的数组长度 + */ +public static void bubbleSort(int [] a, int n){ + // 你的代码,使无序数组 a 变得有序 + ... + ... + +} //end -- Gitee From 22298c381c76b70c0f160e59c032b44c242317db Mon Sep 17 00:00:00 2001 From: piero_choi <1565984532@qq.com> Date: Tue, 15 Apr 2025 20:48:21 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=86=92=E6=B3=A1?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codes/piero_choi/19955133.java | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/codes/piero_choi/19955133.java b/codes/piero_choi/19955133.java index c04f3701..6a6362ae 100644 --- a/codes/piero_choi/19955133.java +++ b/codes/piero_choi/19955133.java @@ -5,8 +5,31 @@ * @param n 待排序的数组长度 */ public static void bubbleSort(int [] a, int n){ - // 你的代码,使无序数组 a 变得有序 - ... - ... + bubbleSort(a, 0, n-1); } //end + +public static void bubbleSort(int [] a, int low, int high) { + + if (low >= high) return; + + int pilot = a[high]; + int i = low; + + for (int j = low; j++; j < high) { + if (a[j] < pilot) { + int tmp = a[j]; + a[j] = a[i]; + a[i] = tmp; + i++; + } + j++; + } + + a[high] = a[i]; + a[i] = pilot; + + bubbleSort(a, low, i-1); + bubbleSort(a, i+1, high); + +} -- Gitee From e152802b892c97d007fef32e41e78ec26c2fd191 Mon Sep 17 00:00:00 2001 From: piero_choi <1565984532@qq.com> Date: Tue, 15 Apr 2025 21:04:34 +0800 Subject: [PATCH 3/3] fix bug --- codes/piero_choi/19955133.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/codes/piero_choi/19955133.java b/codes/piero_choi/19955133.java index 6a6362ae..ca591876 100644 --- a/codes/piero_choi/19955133.java +++ b/codes/piero_choi/19955133.java @@ -16,14 +16,13 @@ public static void bubbleSort(int [] a, int low, int high) { int pilot = a[high]; int i = low; - for (int j = low; j++; j < high) { + for (int j = low; j < high; j++) { if (a[j] < pilot) { int tmp = a[j]; a[j] = a[i]; a[i] = tmp; i++; } - j++; } a[high] = a[i]; -- Gitee