java冒泡排序及优化
import java.util.Arrays; public class TestBubbleSort3 { public static void main(String[] args) { int[] a = {23,45,2,86,56,34,234,54,342}; getBubbleSortResult(a); } public static void getBubbleSortResult(int[] a) { for(int j =0;j<a.length-1;j++) { boolean flag = true; for(int i = 0;i<a.length-1-j;i++) { if(a[i]>a[i+1]) { int tmp = a[i+1]; a[i+1] = a[i]; a[i] = tmp; flag =false; } System.out.println(Arrays.toString(a)); } if(flag == true) { break; } System.out.println("#################"); } } }