diff --git a/codes/it-31i45/18718682.java b/codes/it-31i45/18718682.java new file mode 100644 index 0000000000000000000000000000000000000000..9aa6a9cf88a24c108e9a15b4ffa41636b0e93435 --- /dev/null +++ b/codes/it-31i45/18718682.java @@ -0,0 +1,23 @@ +public class BubbleSort { + public static void bubbleSort(int[] arr) { + int n = arr.length; + for (int i = 0; i < n - 1; i++) { + for (int j = 0; j < n - i - 1; j++) { + if (arr[j] > arr[j + 1]) { + // 交换arr[j]和arr[j + 1] + int temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + } + } + } + } + + public static void main(String[] args) { + int[] arr = {64, 34, 25, 12, 22, 11, 90}; + bubbleSort(arr); + for (int i : arr) { + System.out.print(i + " "); + } + } +}