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

    package xiya;
    import java.util.Arrays;
    public class Example9_3 {
        public static void main(String args[]) {
           String [] a={"boy","apple","Applet","girl","Hat"};
           String [] b=Arrays.copyOf(a,a.length);
           System.out.println("使用用户编写的SortString类,按字典序排列数组a:");
           SortString.sort(a);
           for(String s:a) {
              System.out.print("  "+s);
           }
           System.out.println();
           System.out.println("使用类库中的Arrays类,按字典序排列数组b:"); 
           Arrays.sort(b);
           for(String s:b) {
              System.out.print("  "+s);
           }
        }
    }
    
    package xiya;
    public class SortString {
       public static void sort(String a[]) {
          for(int i=0;i<a.length;i++) {
              for(int j=0;j<a.length-1;j++) { 
                  if(a[j].compareTo(a[j+1])>0) {
                      String temp=a[j];
                      a[j]=a[j+1];
                      a[j+1]=temp;
                  }
              } 
          }
       }
    }
    


  • 相关阅读:
    bzoj3996
    bzoj3157 3516
    bzoj1937
    bzoj1532
    bzoj3572
    bzoj1453
    bzoj3205
    bzoj2595
    关于高斯消元解决xor问题的总结
    linux查找和替换命令
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5835252.html
Copyright © 2011-2022 走看看