I'm trying to figure out why I am able to successfully find strings in my Trie when using keys assigned to Dictionary[] but when I try to create an entirely different string of the same value, I am unable to return a successful search. When trying to figure out why the strings are not the same I created a small block of code to try and troubleshoot the problem. I used key1.compare(key) to show that the strings are not equal, while the compiled code shows that the two strings appear the same. My best guess is that this has something to do with each string having different pointers. My end goal after fixing this issue is to eventually be able to create strings based on an input of characters and search through my Trie data structure containing my dictionary to see if I created a word.
My trie works when I search for strings that are in my dictionary array (this array was used to load the trie), but don't work for when I use any other string outside the original array.
block of code used to test strings
Code copied and pasted:
string key = dictionary[1];
cout << head->search(key) << " ";
string key1 = "the";
cout << head->search(key1) << " ";
cout<< endl<<key<<endl;
cout<< key1<<endl;
if(key1.compare(key)!=1){
cout<<"not equal"<<endl;
}
Compiler: 1 0 the the not equal