zoukankan      html  css  js  c++  java
  • 闲来无事,日常冒泡

     public class BubbleSort {
     2      public static void main(String[] args){
     3                    int score[] = {60,80,75,65,89,90,100,59};
     4                    for (int i=0; i<score.length-1;i++){         //外层控制排序趟数,最多做n-1趟排序
     5                        for(int j=0;j<score.length-i-1;j++){    //内层循环控制每一趟排序多少次
     6                            if(score[j+1] < score[j]){        //把小的值交换到前面
     7                                int temp = score[j];
     8                                score[j] = score[j + 1];
     9                                score[j + 1] = temp;
    10                           }
    11                       }            
    12                       System.out.print("第" + (i + 1) + "次排序结果:");
    13                       for(int a = 0; a < score.length; a++){
    14                           System.out.print(score[a] + "	");
    15                       }
    16                       System.out.println("");
    17                   }
    18                       System.out.print("最终排序结果:");
    19                       for(int a = 0; a < score.length; a++){
    20                          System.out.print(score[a] + "	");
    21                 }
    22              }
    23     }
    

      

  • 相关阅读:
    What Kind of Friends Are You? ZOJ 3960
    博弈随笔(未完待续)
    Mergeable Stack ZOJ
    LIS ZOJ
    差分约束 HDU
    How far away ? HDU
    wya费用流
    不知道说些什么
    ext大法好啊
    bzoj2348
  • 原文地址:https://www.cnblogs.com/DIVEY/p/10682798.html
Copyright © 2011-2022 走看看