Bubble Sort 冒泡排序

时间:2020-12-28 23:45:46
//Bubble Sort ( O(n²))
public class TestBubbleSort { public int[] bubbleSortArray(int[] arr){
for(int i = ; i < arr.length; i ++){
for(int j = ; j < arr.length -i ; j ++){
if(arr[j]>arr[j+]){
int temp;
temp = arr[j];
arr[j] = arr[j+];
arr[j+] = temp;
}
}
}
return arr;
} public static void main(String[] args) {
int[] arr = {,,,,,};
TestBubbleSort test = new TestBubbleSort();
arr = test.bubbleSortArray(arr); for(int i = ; i < arr.length; i ++){
System.out.println(arr[i]);
}
} }

冒泡(Bubble)排序——相邻交换 时间复杂度:( O(n²))