I have some numbers stored in a vector . I want to find which number appears most in the vector.
Is there any easy/fast algorithm (STL or whatever) that does this ?<
Try this
int FindMode(vector value)
{
int index = 0;
int highest = 0;
for (unsigned int a = 0; a < value.size(); a++)
{
int count = 1;
int Position = value.at(a);
for (unsigned int b = a + 1; b < value.size(); b++)
{
if (value.at(b) == Position)
{
count++;
}
}
if (count >= index)
{
index = count;
highest = Position;
}
}
return highest;
}