You are viewing a single comment's thread. Return to all comments →
I think you can use recursion and it makes the class much simpler. Here is what I did with my class.
class Node{
public: map<char, Node> children; bool isCompleteWord; int words; Node() {isCompleteWord = false; words = 0;} void addContact(string s) { words++; if (s.size() == 0) { isCompleteWord = true; } else { children[s[0]].addContact(s.substr(1)); } } int find(string s) { if (s.size() == 0) { return words; } else { return children[s[0]].find(s.substr(1)); } }
};
Seems like cookies are disabled on this browser, please enable them to open this website
Tries: Contacts
You are viewing a single comment's thread. Return to all comments →
I think you can use recursion and it makes the class much simpler. Here is what I did with my class.
class Node{
};