hi all,
I was working on function that counts the word frequency of file,
what i want to do is find the word that occurs the most, so I am not
familiar with generic collections,so i need your help to get this
right ? dict<string, int > ---> <word, occurence>
the alogrithm that I came up is to assume that the first word in the
dictionary to be the most frequent so far and as we go along if we
find a word occurence greater than the one we started with then we
use that as greatest so far and once we get to the end then return
the word that occurs the most and how many times it has been counted.
am i on the right track
public void FindMostFreqWord()
{
largestSofar = word_counter[0];
foreach (KeyValuePair<string, int> kvp in word_counter)
{
if (kvp.Value > largestSofar)
{
largestSofar = kvp.Value;
string word = kvp.Key;
}
}
Console.WriteLine("the most frequent word is " + word_counter);
}
thanks in advance