diff --git a/15824820.java b/15824820.java new file mode 100644 index 0000000000000000000000000000000000000000..53e13500ac840b57ff4c67a5dad4e3646f7b11bb --- /dev/null +++ b/15824820.java @@ -0,0 +1,22 @@ +/** + * 冒泡排序 + * + * @param a 待排序的数组 + * @param n 数组的长度 + */ + public static void bubbleSort1(int[] a, int n) { + int i, j; + + for (i = n - 1; i > 0; i--) { + // 将a[0...i]中最大的数据放在末尾 + for (j = 0; j < i; j++) { + + if (a[j] > a[j + 1]) { + // 交换a[j]和a[j+1] + int tmp = a[j]; + a[j] = a[j + 1]; + a[j + 1] = tmp; + } + } + } + }