/*
	this overloaded addition operator will insert the word w in the dictionary if it's not already there;
	otherwise, it will increase its frequency by 1
*/
DICT DICT::operator+(WORD w)
{
	int pos; // pos is the index location of word
	if ( (pos = LocateWord(w)) >= 0 ) {
		d[pos].freq++;
		return *this;
	} else {
		insert(w); // if not in dictionay, insert word
		return *this;
	}
}
int main (void) {
    int pos;

    while (1) {

       word = GetNextWord();
       if ( 0 == word.length() )  {
           DumpDictionary(dictionary,count);
           break;
       }
       if ((pos = LocateWord(dictionary,word)) >=  0 ) 
           count[pos]++;
       else
           if (!InsertWord(dictionary,word)) cout << "dictionary full " << word << " cannot be added\n";
    }
    return 0;
}
Beispiel #3
0
int main (void) {

    ENTRY *pos;

    while (1) {
       word = GetNextWord();
       if ( word.empty() )  {
           DumpDictionary(dictionary);
           break;
       }
       if ((pos = LocateWord(dictionary,word)) >  0 ) 
           pos->count++;
       else
           if (!InsertWord(dictionary,word)) cout << "dictionary full" << word <<  "cannot be added\n";
    }
    delete pos;
    return 0;
}