public class 冒泡排序 { public void sort(int[] a) { boolean flag = true; for(int i = 0; i < a.length && flag; i++) { flag = false; for(int j = a.length - 1; j >= i; j--) { if(a[j - 1] > a[j]) { int temp = a[j]; a[j] = a[j - 1]; a[j - 1] = temp; flag = true; } } } } }
原文:http://www.cnblogs.com/13jhzeng/p/6017249.html