I need help with counting clumps of numbers
For example, I have a multiset<int> = { 1, 1, 2, 1, 1 };
This would print out 2 since there is a 1 that is consecutive and another 1 that is consecutive.
Another example: I have a multiset<int> = { 1, 2, 2, 3, 4, 4 };
This would print out 2 as well because there is a consecutive of 2 and another consecutive of 4
Another example: I have a multiset<int> = { 1, 1, 1, 1, 1 };
This would print out 1 because there is a consecutive number of 1.
so far, this is what I have for the function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
int countClumps(const multiset<int>& num)
{
multiset<int>::iterator it = num.begin();
multiset<int>::iterator last = num.end();
int count = 0;
for (it; it != last; it++)
{
if (it++ != last)
{
if (*it != *(++it) && *(it--) == *(it--))
{
++count;
}
}
it++;
}
return count;
}
|
My error keeps on saying
map/set iterator not incrementable or
map/set iterator not dereferenceable.