课程代码:
1 // 冒泡排序 2 public static int[] sort(int[] array){ 3 int temp = 0; 4 // 外层循环,判断走多少次 5 for (int i = 0; i < array.length-1; i++) { 6 // 内存循环,判断大小,交换位置 7 for (int j = 0; j < array.length-1-i; j++) { 8 if(array[j+1] > array[j]){ 9 temp = array[j]; 10 array[j] = array[j+1]; 11 array[j+1] = temp; 12 } 13 } 14 } 15 16 return array; 17 18 }
注意点:
1:多看多想。
原文:https://www.cnblogs.com/5huangzi/p/14449667.html