标签:
//冒泡排序 从小到大 int [] a = new int []{23,45,67,12,97,78,8,36}; System.out.print("原始数据 "); for(int t : a) { System.out.print(t + " "); } System.out.println(); //循环次数 for (int j=0; j<a.length-1 ; j++){ //前后比较循环 for (int i =0; i< a.length-1-j; i++) { //比较前后元素的大小顺序 if (a[i]>a[i+1]) { //临时存放 int b =a[i]; a[i]=a[i+1]; a[i+1]=b; } } System.out.print(j+1 + " 次循环 "); for(int t : a) { System.out.print(t + " "); } System.out.println(); }
标签:
原文地址:http://www.cnblogs.com/zk0533/p/5226816.html