diff --git a/activity-school b/activity-school new file mode 160000 index 0000000000000000000000000000000000000000..7e899b2897f5a24b8281efeac3b8ae635162b517 --- /dev/null +++ b/activity-school @@ -0,0 +1 @@ +Subproject commit 7e899b2897f5a24b8281efeac3b8ae635162b517 diff --git a/codes/LEK13514938753/15774825.java b/codes/LEK13514938753/15774825.java new file mode 100644 index 0000000000000000000000000000000000000000..8f44c215bf2bc6836507a79d6c0520a4a6d3caae --- /dev/null +++ b/codes/LEK13514938753/15774825.java @@ -0,0 +1,20 @@ +/** + * 冒泡排序函数 + * 通过重复地遍历待排序的数组,比较每对相邻的元素, + * 如果它们的顺序错误就把它们交换过来,遍历数组的工作是重复地进行直到没有再需要交换, + * 也就是说该数组已经排序完成。 + * @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/activity-school b/codes/activity-school new file mode 160000 index 0000000000000000000000000000000000000000..7d0d78c4d0b52cf5c20383841d1ef54f4e661237 --- /dev/null +++ b/codes/activity-school @@ -0,0 +1 @@ +Subproject commit 7d0d78c4d0b52cf5c20383841d1ef54f4e661237