I am want to code Radix Sort with buckets,
It compiles and runs but is slower than QuickSort ,
I expected to be faster , and for sure I am doing something wrong,
Any suggestion is appreciated .
Thank You
void radixBucketSort(vector<int>& inputData)
{
if(inputData.size() <=1)
return;
vector<int>::iterator intVecIterator;
int maxValue = *(std::max_element(inputData.begin(),inputData.end()));
int significantDigit = 1;
vector< vector<int> >buckets(10);
while(maxValue != 0)
{
for(intVecIterator = inputData.begin(); intVecIterator != inputData.end(); intVecIterator++)
{
int num = *intVecIterator;
if(num < 0)
{
cout << "The vector can not contain negative integers" << endl;
return ;
}
int remainder = (num/significantDigit) % 10;
buckets[remainder].push_back(num);
}
vector<int>::iterator inputDataIterator = inputData.begin();
for(int i = 0; i < 10; i++)
{
for (intVecIterator = buckets[i].begin(); intVecIterator != buckets[i].end(); intVecIterator++)
{
*inputDataIterator = *intVecIterator;
++inputDataIterator;
}
buckets[i].clear();
}