Bucket Sort
unknown
c_cpp
3 years ago
348 B
2
Indexable
Never
void bucketSort(float arr[], int n) { vector<float> b[n]; for (int i=0; i<n; i++) { int bi = n*arr[i]; // Index in bucket b[bi].push_back(arr[i]); } for (int i=0; i<n; i++) sort(b[i].begin(), b[i].end()); int index = 0; for (int i = 0; i < n; i++) for (int j = 0; j < b[i].size(); j++) arr[index++] = b[i][j]; }