冒泡排序
空间复杂度O(1)
时间复杂度O(n2)
public class BubbleSort {
public static void main(String[] args) {
int[] arr = new int[]{1, 5, 7, 4, 36, 2, 21, 465, 45, 213, 456};
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length - i - 1; j++) {
int temp = 0;
if(arr[j]>arr[j+1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
for (int i : arr) {
System.out.print(i+" ");
}
}
}
}
}
}