Thread: bintree and count (withouth using template)?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    30

    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
    Last edited by cubimongoloid; 05-22-2009 at 05:39 PM.

Popular pages Recent additions subscribe to a feed