I have inserted and printed out the bintree (automatically sorted)
but there still one problem
Code:
while (fin.good())
{
getline(fin, temp);
string::const_iterator itr = temp.begin();
while(itr != temp.end())
{
if (isspace(*itr) || *itr == '>' || *itr == '<' || *itr == '!' || *itr == ',')
{
if (word.find(new_word))
{
i++;
new_word.clear();
}
else
{
word.insert(words(new_word));
new_word.clear();
}
}
else
{
new_word += *itr;
}
itr++;
}
}
word.insert(words(new_word)); // this will insert the last word into bintree, but the problem is the last word is
//the same with one of the word exist. The program is terminated.
print(word);
}
}
//print function which called toString above
void print(bintree<words> word)
{
cout << "COUNT | WORD \n";
cout << "------+------\n";
word.print();
cout << "\nNum Nodes is: " << word.numNodes() << endl;
}
Everytime i wanna insert into bintree i have to check it again whether the word is already exist or not.
I'm thinking of a bool function for finding an exsting word then apply to where i wanna insert.
is there any more convinient way to do this???
Thanks