public class Demo {
public static void main(String[] args) {
int arr[];arr=new int[]{16,25,9,90,23};
int temp = 0 ;
boolean flag = false;
for (int i = 0; i < arr.length; i++) {
for (int j = 1; j < arr.length-i; j++) {
if (arr[j-1]>arr[j]){
temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp ;
flag = true ;
}
}
if(!flag){
break;
}
}
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
冒泡排序优化练习(JAVA)
最新推荐文章于 2022-07-15 14:00:24 发布