排序算法-冒泡排序(Java)
1.确定一共要排几轮(i)
2.每轮要排几次(j),次数=数组长度-i
public class maoPaoPaiXu {
public static void main(String[] args) {
int[] arr={5,4,3,2,1};
//循坏轮数
for (int i = 1; i <= arr.length-1; i++) {
for (int j = 0; j < arr.length-i; j++) {
if (arr[j]>arr[j+1]){
int a=arr[j+1];
arr[j+1]=arr[j];
arr[j]=a;
}
}
}
for (int i = 0; i < arr.len
共有 0 条评论