zoukankan      html  css  js  c++  java
  • java冒泡排序

    public class BubbleSort {
        public static void main(String[] args) {
            int score[] = {1,4,5,7,2,3,9,0,6,8};
            for(int i=1;i<score.length;i++){         //最多做n-1趟排序
                for(int j=0;j<score.length-i;j++){   //每次排序范围减少
                    if(score[j]<score[j+1]){
                        //交行2个变量数据的3种方法
    //                    int temp = score[j];
    //                    score[j] = score[j+1];
    //                    score[j+1] = temp;
                        
                        
                        score[j] = score[j]^score[j+1];
                        score[j+1] = score[j]^score[j+1];
                        score[j] = score[j]^score[j+1];
                        
    //                    score[j] = score[j]+score[j+1];
    //                    score[j+1] = score[j]-score[j+1];
    //                    score[j] = score[j]-score[j+1];
                    }
                }
                System.out.print("第" + i + "次排序结果:");
                for(int a=0;a<score.length;a++){
                    System.out.print(score[a]+"	");
                }
                System.out.println("");
            }
            System.out.print("最终0排序结果:");
            for(int a=0;a<score.length;a++){
                System.out.print(score[a]+"	");
            }
        }
    }
  • 相关阅读:
    tcp和udp的区别
    链路聚合配置
    TCP/IP协议
    ip数据报格式
    私有IP地址和公网IP地址
    ipconfig
    ipconfig
    命令更改ip地址2
    命令更改ip地址一
    路由器静态ip设置
  • 原文地址:https://www.cnblogs.com/Nbge/p/4329302.html
Copyright © 2011-2022 走看看