zoukankan      html  css  js  c++  java
  • 冒泡排序,桶排序,快速排序

    /**
    * Copyright © 1998-2018, Glodon Inc. All Rights Reserved.
    */
    package glodon.gfm.exchange.statistic.action;
    
    import java.util.Arrays;
    
    import org.hibernate.annotations.Sort;
    
    import com.sun.tools.javac.code.Attribute.Array;
    
    public class test {
    
        public static void main(String[] args) {
            int[] zonghe = new int[]{1,20,23,9,0,2,39};
            
    //        TongPaixu(zonghe);
    //        maopao(zonghe);
    //        kuaipai(zonghe);
            
            System.out.println("Hello World");
            int[] a = {12,20,5,16,15,1,30,45,23,9};
            int start = 0;
            int end = a.length-1;
            sort(a,start,end);
            for(int i = 0; i<a.length; i++){
                 System.out.println(a[i]);
             }
        }
    
        public static void sort(int[] a,int low,int high){
            int start = low;
            int end = high;
            int key = a[low];
             
            while (end > start) {
                while (end > start && a[end] >= key) {
                    end --;
                }
                if (a[end] < key) {
                    int temp = a[end];
                    a[end] = a[start];
                    a[start] = temp;
                }
                
                while (end > start && a[start] <= key) {
                    start++;
                }
                if (a[start] > key) {
                    int temp = a[end];
                    a[end] = a[start];
                    a[start] = temp;
                }
            }
            
            if (start > low) sort(a,low,start-1);
            if (end < high) sort(a, end+1, high);
         }/**
         * TODO
         * @param zonghe
         */
        private static void maopao(int[] zonghe) {
            for (int i = 0; i < zonghe.length-1; i++) {
                for (int j = 0; j < zonghe.length-1-i; j++) {
                    if (zonghe[j] < zonghe[j+1]) {
                        int temp = zonghe[j];
                        zonghe[j] = zonghe[j+1];
                        zonghe[j+1] = temp;
                    }
                }
            }
            System.out.println(Arrays.toString(zonghe));
        }
    
        /**
         * TODO
         * @param zonghe
         */
        private static void TongPaixu(int[] zonghe) {
            // TODO Auto-generated method stub
            int[] test = new int[40]; 
            
            for (int i = 0; i < zonghe.length; i++) {
                test[zonghe[i]]++;
            }
            
            String string = "";
            for (int i = 0; i < test.length; i++) {
                if (test[i]!=0) {
                    string += i+",";
                }
            }
            System.out.println(string);
        }
    }
  • 相关阅读:
    Android漂亮的对话框项目sweet-alert-dialog
    JAVA并发编程4_线程同步之volatile关键字
    JAVA并发编程3_线程同步之synchronized关键字
    JAVA并发编程2_线程安全&内存模型
    JAVA并发编程1_多线程的实现方式
    JAVA 反射
    第五百三十九天 how can I 坚持
    第五百三十八天 how can I 坚持
    第五百三十七天 how can I 坚持
    第五百三十六天 how can I 坚持
  • 原文地址:https://www.cnblogs.com/liyang19910805/p/9591157.html
Copyright © 2011-2022 走看看