我为我的cs类分配了排序算法。我需要将基数排序的伪代码转换为 c++。这是我的伪代码:
radixSort( int theArray[], in n:integer, in d:integer)
// sort n d-digit integers in the array theArray
for (j=d down to 1) {
Initialize 10 groups to empty
Initialize a counter for each group to 0
for (i=0 through n-1) {
k = jth digit of theArray[i]
Place theArray[i] at the end of group k
Increase kth counter by 1
}
Replace the items in theArray with all the items in
group 0, followed by all the items in group 1, and so on.
}
问题是,我真的不明白“组”是什么意思。我首先尝试使用数组,但当然,它会覆盖数字。如何根据最后一位数字对数字进行分组?我不要求任何代码。我只需要了解。非常感谢。