From befafdddf34359c4f5036a90f9fc588fcf8cabbb Mon Sep 17 00:00:00 2001 From: wangjz <736599796@qq.com> Date: Mon, 24 Oct 2022 21:05:17 +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/fubing3/9622480.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 codes/fubing3/9622480.java diff --git a/codes/fubing3/9622480.java b/codes/fubing3/9622480.java new file mode 100644 index 000000000..4336c2759 --- /dev/null +++ b/codes/fubing3/9622480.java @@ -0,0 +1,23 @@ +/** + * 冒泡排序函数 + * aa bb cc + * @param a 待排序的数组 + * @param n 待排序的数组长度 + */ +public static void bubbleSort(int [] arrays, int n){ + // 你的代码,使无序数组 a 变得有序 + + int temp = 0; + //比较几轮 + for(int i = 0; i < arrays.length - 1; i++) { + for(int j = 0; j < arrays.length - 1 - i; j++) { + if(arrays[j] > arrays[j + 1]) { + temp = arrays[j]; + arrays[j] = arrays[j + 1]; + arrays[j + 1] = temp; + } + } + } + + +} //end -- Gitee From 829df4af67d1d4840f38114b17335f4be78c054d Mon Sep 17 00:00:00 2001 From: wangjz625 <736599796@qq.com> Date: Tue, 25 Oct 2022 09:02:06 +0800 Subject: [PATCH 2/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 --- .../9622480.java => wangjz625/9959126.java} | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) rename codes/{fubing3/9622480.java => wangjz625/9959126.java} (34%) diff --git a/codes/fubing3/9622480.java b/codes/wangjz625/9959126.java similarity index 34% rename from codes/fubing3/9622480.java rename to codes/wangjz625/9959126.java index 4336c2759..677c47daa 100644 --- a/codes/fubing3/9622480.java +++ b/codes/wangjz625/9959126.java @@ -4,20 +4,19 @@ * @param a 待排序的数组 * @param n 待排序的数组长度 */ -public static void bubbleSort(int [] arrays, int n){ +public static void bubbleSort(int [] a, int n){ // 你的代码,使无序数组 a 变得有序 - - int temp = 0; - //比较几轮 - for(int i = 0; i < arrays.length - 1; i++) { - for(int j = 0; j < arrays.length - 1 - i; j++) { - if(arrays[j] > arrays[j + 1]) { - temp = arrays[j]; - arrays[j] = arrays[j + 1]; - arrays[j + 1] = temp; - } - } - } + int temp = 0; + //比较几轮 + for(int i = 0; i < arrays.length - 1; i++) { + for(int j = 0; j < arrays.length - 1 - i; j++) { + if(arrays[j] > arrays[j + 1]) { + temp = arrays[j]; + arrays[j] = arrays[j + 1]; + arrays[j + 1] = temp; + } + } + } } //end -- Gitee From 6410b04cda2b3f4c7ce1cb6a61e42ecb1a4a807c Mon Sep 17 00:00:00 2001 From: wangjz625 <736599796@qq.com> Date: Tue, 25 Oct 2022 11:54:59 +0800 Subject: [PATCH 3/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/wangjz625/9959126.java | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/codes/wangjz625/9959126.java b/codes/wangjz625/9959126.java index 677c47daa..74942c4e7 100644 --- a/codes/wangjz625/9959126.java +++ b/codes/wangjz625/9959126.java @@ -3,20 +3,18 @@ * aa bb cc * @param a 待排序的数组 * @param n 待排序的数组长度 - */ -public static void bubbleSort(int [] a, int n){ +public static void bubbleSort(int[] a, int n) { // 你的代码,使无序数组 a 变得有序 - int temp = 0; - //比较几轮 - for(int i = 0; i < arrays.length - 1; i++) { - for(int j = 0; j < arrays.length - 1 - i; j++) { - if(arrays[j] > arrays[j + 1]) { - temp = arrays[j]; - arrays[j] = arrays[j + 1]; - arrays[j + 1] = temp; - } - } - } - - + int i, j; + for (i = 0; i < n; i++) {//表示n次排序过程。 + for (j = 1; j < n - i; j++) { + if (a[j - 1] > a[j]) {//前面的数字大于后面的数字就交换 + //交换a[j-1]和a[j] + int temp; + temp = a[j - 1]; + a[j - 1] = a[j]; + a[j] = temp; + } + } + } } //end -- Gitee