经典算法:基数排序的小例子

2019-05-20 12:18:44王旭

                {
                    int tmpSplitDigit = nums[i] / (int)Math.Pow(10, k - 1) - (nums[i] / (int)Math.Pow(10, k)) * 10;
                    tmpCountingSortArray[tmpSplitDigit]++;
                }
                for (i = 1; i < tmpCountingSortArray.Length; i++)
                {
                    tmpCountingSortArray[i] += tmpCountingSortArray[i - 1];
                }
                for (i = nums.Length - 1; i >= 0; i--)
                {
                    int tmpSplitDigit = nums[i] / (int)Math.Pow(10, k - 1) - (nums[i] / (int)Math.Pow(10, k)) * 10;
                    tmpArray[tmpCountingSortArray[tmpSplitDigit] - 1] = nums[i];
                    tmpCountingSortArray[tmpSplitDigit]--;
                }
                for (i = 0; i < nums.Length; i++)
                {
                    nums[i] = tmpArray[i];
                }
            }
        }
            //int[] list = new[] { 16, 14, 10, 8, 7, 9, 3, 2, 4, 1 };
            //Sorter.RadixSort(list, 2);