【发布时间】:2012-02-09 23:42:43
【问题描述】:
试图了解我的数据结构类的基数排序。我的老师向我们展示了 C++ 中的基数排序示例。我不明白数字的 for 循环是做什么的,她说了一些关于最大数字的事情。此外,当我在 VS 中尝试此操作时,它说 log10 是对重载函数的模棱两可的调用。
void RadixSort(int A[], int size)
{
int d = 1;
for(int i = 0; i < size; ++i)
{
int digits_temp;
digits_temp=(int)log10(abs(A[i]!=0 ? abs(A[i]) : 1)) +1;
if(digits_temp > d)
d = digits_temp;
}
d += 1;
*rest of the implementation*
}
谁能解释这个 for 循环的作用以及为什么我得到那个模棱两可的调用错误?谢谢
【问题讨论】:
-
放置其余代码?这部分只从所有数字中找到最大位数
标签: c++ algorithm data-structures radix-sort