package pro;
public class pro {
public static void bubbleSort(int[] a) {
for (var i = 0; i < a.length - 1; i++) {
for (var j = 0; j < a.length - i - 1; j++) {
if (a[j] > a[j + 1]) {
int t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
System.out.print("第" + (i+1) + "趟结果:");
for(var n:a) {
System.out.print(" " + n);
}
System.out.println();
}
}
public static void main (String[] args){
int[]nums = {75, 53, 32, 12, 46, 199, 17, 54};
//int[]nums = {199,75, 54,53, 46,32, 17, 12 };
System.out.print("初始元素:");
for(var n:nums) {
System.out.print(" " + n);
}
System.out.println();
bubbleSort(nums);
}
}