private static int[] bubbleSort(int[] array) {
int num = array.length;
for (int i = 0; i < num - 1; i++) {
for (int j = i + 1; j < num; j++) {
if (array[i] >= array[j]) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
System.out.println("第" + (i + 1) + "次:");
for (int m = 0; m < num; m++) {
System.out.print(array[m] + "\t");
}
System.out.println("");
}
System.out.println("结果:");
for (int m = 0; m < num; m++) {
System.out.print(array[m] + "\t");
}
return array;
}
冒泡排序
最新推荐文章于 2022-04-29 23:24:15 发布