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

/**
* 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);
    }
}
原文地址:https://www.cnblogs.com/liyang19910805/p/9591157.html