What my main doubt is that whenever I try passing the root node as a default value in the insertWord
function it throws a compilation error. I do not know where I am going wrong. If somebody could help me. Thank you.
#include <iostream>
#include <string>
using namespace std;
class TrieNode {
public:
char data;
TrieNode** children;
bool isTerminal;
TrieNode(char data) {
this->data = data;
children = new TrieNode*[26];
for (int i = 0; i < 26; i++) {
children[i] = NULL;
}
isTerminal = false;
}
~TrieNode() {
for (int i = 0; i < 26; i++) {
delete children[i];
}
}
};
class Trie {
private:
TrieNode* root;
Trie() { root = new TrieNode('\0'); }
void insertWord(string word, TrieNode* node = root) {}
};
int main() {
cout << "Hello World";
return 0;
}