Bucket Sort

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
348 B
1
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];
}