Reputation: 3
I'm trying to make a .Count with max function inside to get how many times the max value from a float type. From MSDN I didn`t understand how to make it. Any ideeas?
Upvotes: 0
Views: 362
Reputation: 1152
Something like that? (Maybe not, it was hard to understand the question)
int count(std::vector<float> &data) {
if ( data.empty() ) return -1;
float maxval = data[0];
int maxnum = 0;
for ( std::vector<float>::iterator it = data.begin()+1; it != data.end(); ++it ) {
if ( equal(*it, maxval) ) {
maxnum += 1;
} else if ( *it > maxval ) {
maxval = *it;
maxnum = 0;
}
}
return maxnum;
}
equal(a, b) checks if |a - b| <= epsilon
Upvotes: 2