冒泡排序(基础版)
冒泡排序
public class bubbleSort {
public static void main(String[] args) {
int[] arr = {12, 33, 45, 6, 78, 9};
sort(arr);
System.out.println(Arrays.toString(arr));
}
public static int[] sort(int[] array) {
int temp;
//外圈 决定循环次数
for (int i = 0; i < array.length - 1; i++) {
//内圈 决定大小
for (int j = 0; j < array.length - 1 - i; j++) {
if (array[j] > array[j + 1]) {
temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;
}
}
}
return array;
}
}