• 冒泡排序,桶排序,快速排序


    /**
    * 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);
        }
    }
  • 相关阅读:
    node 日志 log4js 错误日志记录
    使用sync 修饰符------子组件内部可以修改props
    rem是怎么计算的
    你真的了解word-wrap和word-break的区别吗? (转载)
    vue-router学习笔记
    vue学习笔记
    es6学习笔记
    vue中在页面渲染完之后获取元素(否则动态渲染的元素获取不到)
    flex布局居中无效果注意是否设置了宽度
    有关vuex的问题
  • 原文地址:https://www.cnblogs.com/liyang19910805/p/9591157.html
Copyright © 2020-2023  润新知