Hello, I've been trying to get this Trie program to work for a while, and keep getting the same error "Use of undeclared identifier" for the four functions in my class. I think the header file is set up correctly, and I've used scope resolution operators for each function in the .cpp file. I cannot figure out what else is causing this problem. All help is appreciated!
#include <iostream>
#include <string>
#include "TrieNode.h"
using namespace std;
int main()
{
string keys[] = {"sunny", "raining", "happy", "sad"};
int n = sizeof(keys)/sizeof(keys[0]);
TrieNode *root = getNode();
// Construct trie
for (int i = 0; i < n; i++)
insertNode(root, keys[i]);
for (int i = 0; i < ALPHABET_SIZE; i++)
nodePointer->children[i] = NULL;
return nodePointer;
}
void TrieNode::insertNode(TrieNode *root, string word)
{
TrieNode *searchPointer = root; //points to the trie we are working with
for (int i = 0; i < word.length(); i++)
{
int index = word[i] - CASE;
if (!searchPointer->children[index])
searchPointer->children[index] = getNode();
searchPointer = searchPointer->children[index];
}
searchPointer->isEndOfWord = true;
}
bool TrieNode::searchTrie(TrieNode *root, string word)
{
TrieNode *searchPointer = root;
for (int i = 0; i < word.length(); i++)
{
int index = word[i] - CASE;
if (!searchPointer->children[index])
return false;
I'm not sure what the getNode() function is supposed to do but it's not working. You declare a null pointer and then you try to use it to access stuff but that won't work because null means the pointer doesn't point to anything.