I need help to get a functioning code for bucketSort in C++; all codes on internet are somehow not executable.
What does this operator [] in front of vector (bucket) do? I know it creates n buckets but I am not sure if it creates n subvectors within the main vector bucket!
furthermore I can't figure out why the code is not working, please help me with that. Thank you in advance.
#include <iostream>
#include <vector>
#include <algorithm
#include <iterator>
using namespace std;
void bucketSort (vector <int> &v){
int n;
v.resize(n)
vector<int> buckets[v];
for (int i=0; i<n; i++)
{
int correctIndex = n*v[i];
buckets[correctIndex].push_back(v[i]);
}
for (int i=0; i<n; i++)
{
sort(buckets[i].begin(), buckets[i].end());
}
int index = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < buckets[i].size(); j++)
arr[index++] = b[i][j];
}
}