Looking for help. As I am trying to get user's input, which is string. Then, compare the string that matched the word variable in myBST then print out. Unfortunately, my binary search tree holds a class named WordApp, that consists of int frequency; string word.
Which I am trying to compare user input that match with word variable from WordApp object, but I do not have direct access to it. Here is the definition of WordApp.
class WordApp{
int frequency;
string word;
string processText(string &);
public:
void setWord(string);
void setFrequency(int);
string getWord();
int getFrequency();
void scanText();
WordApp();
bool operator>(WordApp);
friend ostream& operator <<(ostream& out, WordApp result) //To overload "<<" cout operator in order to use .inOrderPrint()
{
out << "(" << result.word << ", " << result.frequency << ")" << endl;
return out;
}
bool WordApp::operator>(WordApp result) //To overload ">" greater than operator that used in BST class, insert()
{
if (this->frequency > result.getFrequency())
{
return 1;
}
else if (this->frequency == result.getFrequency())
{
if (this->word.compare(result.word) > 0)
{
return 1;
}
}
return 0;}
In my binary search tree, which I have declared as below to store WordApp objects
WordApp myWord;
BST<WordApp> myBST;
myBST.insert(myWord);
string input;
cout << "Query: ";
cin >> input;
cout << myBST.Traversal(input) << endl; //search function doesn't take string as argument since myBST<WordApp> but not myBST<string>
While below is my Traversal function implemented in binary search tree
template<class T>
bool BST<T>::Traversal(T result)
{
if (root == NULL)
{
return 0;
}
Traversal2(root, result);
return 1;
}
template<class T>
bool BST<T>::Traversal2(BTNode<T> *cursor, T result)
{
if (cursor == NULL)
{
return;
}
if (cursor->item > result)
{
Traversal2(cursor->left, result);
}
else
{
Traversal2(cursor->right, result);
}
return cursor->item;
}
As statement myBST.search(input) is comparing an input a string variable to a object class, which is unrecognized. I tried to think but getting nowhere. Can anyone please help on this?