From 643338574a69913c78a00c740b31220d3c9222e5 Mon Sep 17 00:00:00 2001 From: a7042152007 <14260892+a7042152007@user.noreply.gitee.com> Date: Thu, 4 Apr 2024 20:44:24 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20a5812d8=20from=20https://gitee.com/a704?= =?UTF-8?q?2152007/activity-school/pulls/1551=20=E6=B7=BB=E5=8A=A0?= =?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 --- 15775466.java | 37 ++++++++++++++++++++++++++++ codes/a007123456/.15775466.java.swp | Bin 0 -> 12288 bytes 2 files changed, 37 insertions(+) create mode 100644 15775466.java create mode 100644 codes/a007123456/.15775466.java.swp diff --git a/15775466.java b/15775466.java new file mode 100644 index 00000000..24d38d0c --- /dev/null +++ b/15775466.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 diff --git a/codes/a007123456/.15775466.java.swp b/codes/a007123456/.15775466.java.swp new file mode 100644 index 0000000000000000000000000000000000000000..4c6895e77a3dea656e5e429a735b9688ae3842a9 GIT binary patch literal 12288 zcmeI%JC4FI5P;!<9xZ|k@TegV5{D~nu_Y9ACV&Va8HErn6id5T;xrs(H{nqsDAIv` zOZLc?JQ{zJ3(I4B`1#f7cWud9H6JeR_$v|{licRdVl>*$l;@;MuhiaO%;WE6?CwW* zTYmC{mJX9Bjgnnw6V8oUS)rLsH