算法

 基数排序

public  void BaseSord(int[] numbers ,int bits)
    {
        int m = 1;
        int n =1;
        int k = 0;
        int length=numbers.Length;
        int[,]  temp=new int[10,length];
        int[] arrOrder = new int[10];
        while (m <= bits)
        {
            //把数据分到桶里面 length次循环
            for (int i = 0; i < length; i++)
            {
                int index = (numbers[i] / n) % 10;
                temp[index, arrOrder[index]] = numbers[i];
                arrOrder[index]++;
            }
            //把数据放回数组里面 length次循环
            for (int i = 0; i < 10; i++)
            {
                if (arrOrder[i] != 0)
                {
                    for (int j = 0; j < arrOrder[i]; j++)
                    {
                        numbers[k] = temp[i, j];
                        k++;
                    }
                }
                //回复数据初始状态
                arrOrder[i] = 0;
            }
            n *= 10;
            m++;
            k = 0;

        }
    }

posted @ 2014-07-24 11:00  寻天崖子  阅读(151)  评论(0编辑  收藏  举报