桶排序的变种--链式基数排序--麻将应用

import org.junit.Test;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by wc on 2018/4/28.
 */

public class 链式基数排序 {

    @Test
    public void test(){
        LinkedList list=new LinkedList<>();
        list.add(new MaJiang(1,6));
        list.add(new MaJiang(3,2));
        list.add(new MaJiang(2,5));
        list.add(new MaJiang(6,4));
        list.add(new MaJiang(5,7));
        list.add(new MaJiang(4,9));
        list.add(new MaJiang(9,9));
        list.add(new MaJiang(8,8));
        List list1 = sort(list);
        System.out.println(list1.toString());
    }

    /**
     * 桶排序的变种
     */
    public List sort(LinkedList list){
        //先对点数进行分组
        List listRank=getMergeList(list,9,true);
        List listSuit=getMergeList(list,9,false);

        return listSuit;
    }

    public List getMergeList(LinkedList list,int n,boolean flag){
        LinkedList[] l=new LinkedList[n];

        for(int i=0;i0){
            MaJiang maJiang = list.remove();
            if(flag){
                l[maJiang.rank-1].add(maJiang);
            }else{
                l[maJiang.suit-1].add(maJiang);
            }

        }
        for(int i=0;i

你可能感兴趣的:(桶排序的变种--链式基数排序--麻将应用)