冒泡法排序

public class bubbling {

  public static void main(String[] args) {

  int[] nums = {23,34,2,3,44,53,29,22,45};
  for(int i=0;i<nums.length-1;i++){
    for(int j=0;j<nums.length-1-i;j++){
      if(nums[j] > nums[j+1]){
        int temp;
        temp = nums[j];
        nums[j] = nums[j+1];
        nums[j+1] = temp;
       }
      }
     }
  System.out.println("排序后的顺序是:");
  for(int num :nums){
  System.out.println(num);
     }
  }

}

 

posted @ 2016-05-16 22:19  -王志文-  阅读(110)  评论(0)    收藏  举报