I'm trying to use a private function called sortLetters that sorts a string in alphabetical order.
This is the entire code with sortedLetters at the bottom, and I call it in the constructor:
#include "scrabbleAssistant.h"
#include <algorithm>
#include <stdexcept>
using namespace std;
ScrabbleAssistant::ScrabbleAssistant(vector<string> words) {
for(int i = 0; i < words.size(); i++){
this->scrabbleHash.insert(words[i],words[i]);
}
//creating the dictionary for anagrams
for(int i = 0; i < words.size();i++){
string sortedString = this->sortLetters(words[i]);
if(!anagramDict.contains(sortedString)){
vector<string> newAnagramVector;
newAnagramVector.push_back(words[i]);
this->anagramDict.insert(sortedString,newAnagramVector);
}else{
vector<string> anagramVector = this->anagramDict.get(sortedString);
anagramVector.push_back(words[i]);
anagramDict.update(sortedString,anagramVector);
}
}
}
ScrabbleAssistant::~ScrabbleAssistant() {
// TODO: implement destructor
}
bool ScrabbleAssistant::spellCheck(string word) {
if(this->scrabbleHash.contains(word)){
return true;
}
return false;
}
vector<string> ScrabbleAssistant::anagramsOf(string letters) {
throw runtime_error("Not yet implemented");
}
vector<string> ScrabbleAssistant::findWords(string letters) {
throw runtime_error("Not yet implemented: ScrabbleAssistant::findWords");
}
vector<string> stringPowerSet(string letters){
vector<string> result;
//base case: return empty set if letters is empty
if(letters == ""){
result.push_back("");
return result;
}
char firstChar = letters[0];
string sub = letters.substr(1);
//recursive case: find subset of last n-1 elements in set
vector<string> smallerResult = stringPowerSet(sub);
for(int i = 0; i < smallerResult.size(); i++){
result.push_back(smallerResult[i]); // recursive results
result.push_back(firstChar+smallerResult[i]); // append first element
}
return result;
}
string sortLetters(string s){
sort(s.begin(), s.end());
return s;
}
I also declared it in the .h file as such:
string sortLetters(string s);
I'm just wondering why I'm getting this error. llllllllllll