Java - 冒泡排序的優化算法(尚學堂第七章數組)
阿新 • • 發佈:2019-04-17
nbsp test args array 冒泡排序 i++ 排序 println style
import java.util.Arrays; public class TestBubbleSort2 { public static void main(String[] args) { int[] values = { 3, 1, 6, 2, 9, 0, 7, 4, 5, 8 }; int temp = 0; for(int i=0;i<values.length-1;i++) { boolean flag = true; for(intj=0;j<values.length-1-i;j++) { if(values[j] > values[j+1]) { temp = values[j]; values[j] = values[j+1]; values[j+1] = temp; flag = false; } System.out.println(Arrays.toString(values)); }if(flag) { break; } System.out.println("#####################"); } } }
Java - 冒泡排序的優化算法(尚學堂第七章數組)