I have this bucket/radix sort i'm hacking away at and i can't make it work at all. I am trying to implement the algorithm to sort it in ascending order from A through Z for words in a struct. I'm honestly stuck!
Code:
//the struct
struct Wrd {
int wordCounter; //number of times a word exists
string theword; //the actual word
};
//the sort
void bucketSort(vector<Wrd>& V, int start, int stop, int pos){
int i, j, k, index;
vector<Wrd> buckets (27);
// bin 26 is reserved for strings shorter than the current length
// push all of the V into the right bins
for(start = 0; start < stop; start++){
if(V[i].theword.size() <= pos){
buckets[26].push_back(V[i].theword);
} else {
index = int(V[i].theword[pos] -'a');
buckets[index].push_back(V[i].theword);
}
}
// take them out of the bins and put them back into the list
j = 0;
for(i = 0;i <= 26; i++) {
for(k = buckets[start]; k! = buckets[stop]; k++) {
V[j].theword = *k;
j++;
}
}
}
//the call
bubbleSort(V, 0, size);