vector<vector<string>> findLadders(string beginWord, string endWord, unordered_set<string> &wordList) { unordered_map<string, vector<vector<string> > > minPath; priority_queue<pair<int, string> > q([](const pair<int, string> &a, const pair<int, string> &b){ return a.first < b.first; }); q.push(make_pair(beginWord, wordDistance(beginWord, endWord))); vector<vector<string> > beginwordVector; beginwordVector.push_back(vector<string>(1, beginWord)); minPath[beginWord] = beginwordVector; while(q.size()){ auto element = q.top(); q.pop(); auto elementVector = minPath[element]; vector<string> neighbors; for(auto w:wordList){ if(wordDistance(w, element)==1){ neighbors.push_back(w); } } } }
double OptionsFunctionalityNode::getBestMatches(const std::string & word, const std::vector<std::string> &dictionary, std::vector<std::string> &suggestions, int amount) { // Make a list of (word,score) tuples std::vector< std::pair<std::string,double> > candidates(dictionary.size()); // Fill this list for (int i=0;i<dictionary.size();i++) { candidates[i].first = dictionary[i]; candidates[i].second = wordDistance(word,dictionary[i]); } // Sort it sort (candidates.begin(), candidates.end(), mysorter); // Put the first 'amount' of them in suggestions suggestions.clear(); for (int i=0;i<amount;i++) { if (i<candidates.size()) { suggestions.push_back(candidates[i].first); } } return -1; // No score metric yet }