算法排序的思想
先放一段冒泡排序的代码
public class Test { public void bubbleSort(int[] a){ if (a.length<=1){return;} for (int i = 0; i < a.length; i++) { boolean flag = false; for (int j = 0; j < a.length - i - 1; j++) { int tmp = a[j]; if (a[j]>a[j+1]){ a[j]=a[j+1]; a[j+1] = tmp; flag = true; } } if (flag==false){ return; } } } public static void main(String[] args) { int[] q = {10,20,3,2,4,6,7,5}; Test test = new Test(); test.bubbleSort(q); System.out.println(Arrays.toString(q)); } }