首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基数排序:“group”在基数排序中是什么意思?

基数排序:“group”在基数排序中是什么意思?
EN

Stack Overflow用户
提问于 2013-03-04 02:10:20
回答 1查看 299关注 0票数 0

我的cs类有排序算法分配。我需要将基数排序的伪代码转换为c++。下面是我的伪代码:

代码语言:javascript
复制
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.
    }

问题是,我真的不明白“组”是什么意思。我尝试先处理数组,但是,当然,它覆盖了数字。如何根据数字的最后一位数对数字进行分组?我没有要求任何代码。我只想弄明白。非常感谢。

EN

回答 1

Stack Overflow用户

发布于 2014-04-11 09:31:09

取每个数字,除以10的x的幂,x是循环的每次迭代,然后将该数字除以10。

代码语言:javascript
复制
(num/10**x) % 10

这将在第一次传递时给出最低有效位,然后按从右到左的顺序移动到每个数字。迭代次数应等于最大值的长度。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15188955

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档