java基础笔记之冒泡排序
package test;
import java.util.Arrays;
public class _04冒泡排序 {
public static void main(String[] args) {
int[] num = new int[] {6,4,32,754,43,54};
//总共n个数组比较n-1轮
for (int i = 1; i < num.length; i++) {
for (int j = 0; j < num.length-i; j++) {
if(num[j]>num[j+1]) {
int num1 =num[j];
num[j]=num[j+1];
num[j+1]=num1;
}
}
}
System.out.println(Arrays.toString(num));
}
}
如果需要倒序改变一下if里面的大于小于符号即可,这里没有图,有图方便理解,下方有链接。
冒泡排序:https://blog.csdn.net/lu_1079776757/article/details/80459370
十大排序方法:https://www.jianshu.com/p/1af509b2be08