3

I am currently using string::find to search for words stored in a priority queue. How could i make my search case insensitive? This is my current code:

vector<TreeNode> matches;
for (int i=0; i<wordQueue.size(); i++) {
    if (wordQueue.top().key.find(a) == 0){
        matches.push_back(wordQueue.top());
    }
    wordQueue.pop();
}

This is TreeNode:

struct TreeNode {
    string key;
    int data;
}

wordQueue is a priority queue populated with TreeNode datatype:

priority_queue<TreeNode> wordQueue;
void holdWord(TreeNode t) {
    wordQueue.push(t);
}
nanjero echizen
  • 231
  • 4
  • 13
  • If you make both the subject string and the search string lower-case, then the searching will be case-insensitive. (BTW, that loop looks a bit wonky with `i` increasing and `wordQueue.size()` decreasing, meaning you miss about half the queue. Shouldn't it just be `while (!wordQueue.empty() )`?) – Biffen May 16 '16 at 07:56
  • A good question; answer is in the duplicate. – Bathsheba May 16 '16 at 07:59
  • @Biffen You were right thank you for noticing that. – nanjero echizen May 16 '16 at 10:03

0 Answers0