void lx05() {
//冒泡排序 升序
int arr[] = {1,3,2,6,7};
//定义空容器,用于交换
int temp = 0;
for(int i = 0;i < arr.length - 1;i++){
for (int j = 0; j < arr.length-i-1; j++) {
if(arr[i] > arr[i+1]){
temp = arr[i+1];
arr[i+1] = arr[i];
arr[i] = temp;
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
网友评论