• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Bucket sorting in C++

here's c++ implementation and a driver (using map<...> class as bucket holder). ask away if you have any questions.


void bucket_sort(double a[], int n)
{
int k, j = 0;

map<double, int> buckets;

for(k=0; k<n; k++)
buckets[a[k]]++;

map<double, int>::iterator it = buckets.begin( );
while(it != buckets.end( ))
{
for(k=0; k<it->second; k++)
a[j++] = it->first;
it++;
}
}

int main(int argc, char* argv[])
{
double a[] = { 4, 5, 1, 5, 11, 4, 11, 7, 9, 0.1, 1, 6, 453.1, 23.1, 34.12, 33.22, 4, 6.0, 1.0, 1.0 };
bucket_sort(a, 20);
return 0;
}


grrrr, [i.]s are converted to italics 🙂
 
Back
Top