【Java】这个是不是真正的冒泡?

wangyang05 发布于 2012/09/06 15:28
阅读 151
收藏 0
package p0905;
/** 冒泡排序*/
import java.util.Arrays;
public abstract class RealBubbleTest {
 public static int count = 0;
 public static void Sort(int temp[]){
  
  for (int i = 0; i < temp.length; i++) {
   for (int j = 0; j < temp.length-1; j++) {
    if(temp[j]>temp[j+1]){
     
     int x = temp[j];
     temp[j] = temp[j+1];
     temp[j+1] = x;
     }
    System.out.println("第"+(i+1)+"轮:"+Arrays.toString(temp));
    count++;
    }
       }
  System.out.println("一共排了"+count+"次");
    }
 
 public static void Print(int temp[]){
  System.out.print("排序结果:");
  for (int i = 0; i < temp.length; i++) {
   System.out.print(temp[i]+" ");
  }
  }
 public static void main(String[] args) {
  int age[]={38,25,43,27,66,44};
  Sort(age);
  Print(age);
 }

} 
加载中
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部