1 /**
2 * 功能:改进的冒泡排序 原理:不断的交换,每次选出最小的一个放在最前面 冒泡排序时间复杂度:(1)最好的情况下,为o(n) (2)最坏的情况下为o(n^2)
3 */
4 public class BuddleSort {
5
6 public int[] buddleSort(int[] array) {
7 int temp = 0;
8 boolean status = true;
9
10 for (int i = 0; i < array.length & (status == true); i++) {
11 status = false;
12 for (int j = array.length - 1; j > i; j--) {
13 if (array[j] < array[j - 1]) {
14 temp = array[j];
15 array[j] = array[j - 1];
16 array[j - 1] = temp;
17 status = true;
18 }
19 }
20 }
21
22 return array;
23 }
24 }