我正在开发一个程序来使用基数排序对数字列表进行排序,但我一直陷入我认为是无限循环的困境。我认为它要么是我的主要排序功能,要么是我的计数功能。关于我做错了什么的任何想法?
void radix_sort(DLList& list)
{
DLList lstRay[10];
int ct = count(list);
int zeros = 0;
int tmp = 0;
int head = 0;
for(;ct >= 0; ct--)
{
while(!list.isEmpty())
{
head = list.deleteHead();
tmp = head / pow(10, zeros);
tmp = tmp % 10;
lstRay[tmp].addToTail(head);
}
for(int x = 0; x <=9; x++)
{
list.append(lstRay[x]);
}
zeros++;
}
}
int count(DLList& list)
{
int ct = 0;
int ct2 = 0;
int tmp = 0;
while(!list.isEmpty())
{
ct = ct2;
tmp = list.deleteHead();
while(tmp >= 0)
{
tmp = tmp/10;
ct2++;
}
if(ct2 < ct)
{
ct2 = ct;
}
}
return ct2;
}