package algorithm;
import java.util.Arrays;
public class Bubble {
public static void main(String[] args) {
int[] aa=new int[] {1,5,4,3,10};
System.out.println(Arrays.toString(sort(aa)));
}
public static int[] sort(int[] old) {
int count =0;
int i = old.length;
boolean change;
do {
change = false;
for (int j = 1; j < i; j++) {
count++;
if (old[j] < old[j - 1]) {
int temp = old[j];
old[j] =old[j-1];
old[j-1] =temp;
change =true;
}
}
i--;
} while (i > 1 && i < old.length && change);
System.out.println(count);
return old;
}
}
这种冒泡排序的算法时间复杂度 O(n) = T(f(n))
来源:CSDN
作者:daxian_am461
链接:https://blog.csdn.net/daxian_am461/article/details/103608925