package com.beijing.xiaowen.Array;
import java.util.Arrays;
public class Test01 {
public static void main(String[] args) {
//冒泡排序
int[] abc = {3,5,1,6,7,2,9,4};
int[] ints = method01(abc);
System.out.println(Arrays.toString(ints));
}
static int[] method01(int[] a){
int mid = 0;
//决定外部循环次数
for (int i = 0;i<a.length-1;i++){
//两两比较,小的左移;减 i 的目的是为了减少循环次数
for (int j = 0;j<a.length-1-i;j++){
if (a[j]>a[j+1]){
mid = a[j];
a[j] = a[j+1];
a[j+1] = mid;
}
}
}
return a;
}
}
标签:abc,数组,int,mid,冒泡排序,static,ints
From: https://www.cnblogs.com/always0708/p/16808374.html