class Node {
public:
char data;
unordered_map<char, Node*> children;
bool terminal;
int count;
Node(char d) {
data = d;
terminal = false;
this->count = 0;
}
};
class Trie {
Node*root;
int cnt;
public:
Trie() {
root = new Node(’\0’);
cnt = 0;
}
void insert(char *w) {
Node*temp = root;
for (int i = 0; w[i] != '\0'; i++) {
char ch = w[i];
if (temp->children.count(ch)) {
temp->children[ch]->count += 1;
temp = temp->children[ch];
}
else {
Node*n = new Node(ch);
temp->children[ch] = n;
temp = n;
temp->count = 1;
}
}
temp->terminal = true;
}
};
the count of nodes isn’t getting incremented