I'm trying to find the mode of a vector full of ints. To do so I created a map an tried to make it so that evey time a number occurs it increments the related key on the map. Right now I'm just getting the highest number in the vector instead of the number that occurs the most.
map<int,unsigned> frequencyCount;
//This is my attempt to increment the values of the map everytime one of the same numebers
for(size_t i = 0; i < v.size(); ++i)
frequencyCount[v[i]]++;
unsigned currentMax = 0;
unsigned checked = 0;
for(auto it = frequencyCount.cbegin();
it != frequencyCount.cend(); ++it )
checked = it->first;
if (checked > currentMax)
{
currentMax = checked;
}
cout << " The highest value within the map is: " << currentMax << endl;