From da86ba17b1e4ced8500169a20a2bc6294d18511d Mon Sep 17 00:00:00 2001 From: guzy <838822672@qq.com> Date: Tue, 21 Jul 2026 04:08:34 +0000 Subject: [PATCH] =?UTF-8?q?#IK2IEV=20=E5=AE=8C=E6=88=90Java=E5=86=92?= =?UTF-8?q?=E6=B3=A1=E6=8E=92=E5=BA=8F=E7=AE=97=E6=B3=95=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: guzy <838822672@qq.com> --- codes/guzy/IK2IEV.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 codes/guzy/IK2IEV.java diff --git a/codes/guzy/IK2IEV.java b/codes/guzy/IK2IEV.java new file mode 100644 index 000000000..c7fcc0c92 --- /dev/null +++ b/codes/guzy/IK2IEV.java @@ -0,0 +1,30 @@ +public class IK2IEV { + public static void bubbleSort(int[] arr) { + if (arr == null || arr.length <= 1) { + return; + } + int len = arr.length; + for (int i = 0; i < len - 1; i++) { + boolean swapFlag = false; + for (int j = 0; j < len - 1 - i; j++) { + if (arr[j] > arr[j+1]) { + int temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + swapFlag = true; + } + } + if (!swapFlag) break; + } + } + public static void main(String[] args) { + int[] testArr = {6, 2, 9, 1, 5, 3}; + System.out.println("排序前:"); + for(int num : testArr) System.out.print(num + " "); + + bubbleSort(testArr); + + System.out.println("排序后:"); + for(int num : testArr) System.out.print(num + " "); + } +} \ No newline at end of file -- Gitee