bintree and count (not adding any template)?
Hi all!
sorry, title is using existing template.
I wanna add words into a bintree with count with them. If the word is already existed it will increase 1.
first my words class has 2 variable
Code:
class words
{
private:
string s;
int count;
public:
words() : s(""), count(1)
{}
words(const string st, int counting) : s(st), count(counting)
{}
string getWord() const
{
return s;
}
int getCount()
{
return count;
};
then i define bintree to add words into bintree
Code:
bintree<words> word;
words* dup = word.find(words(new_word)); // error here. How can i find only new_word matching without count
string::const_iterator itr = letter.begin();
while (itr != letter.end())
{
if (ispunct(*itr) || isspace(*itr) || *itr == '\n')
{
count++; // increasement for count
if (!dup) // if not duplicate set count back to 1
{
count = 1;
word.insert(words(new_word, count));
new_word.clear();
}
}
else
{
new_word += *itr;
}
itr++;
}
if (!dup)
{
count = 1;
word.insert(words(new_word, count));
new_word.clear();
}
else
count++;
first: how can i find() only new_word in bintree without count?
second: how can i insert() count only into existing word?
Thx and regard