is not true, then tempcounter is not reset to zero, which is wrong.
P.S. You can avoid passing the size of the vector as a parameter: you can just use arr.size().
P.P.S. This algorithm seems quite inefficient: if an element is repeated in your array, it is checked many times. This happens because for every element you repeat the analysis from the beginning. Instead you could find a way to avoid doing so...
1. tempCounter = 0; should go at the beginning of the outer for loop
2. 'counter' should be named 'max' or 'maxcounter' (it is not a counter at all)
3. dont make size a parameter of the mode founction, instead use the statement:
int size = int(arr.size());
at the beginning of the function
4. With your method of finding mode, calling sort is actually unnecessary
@Kevin C @minomic
thank you for your help!
and @Kevin C
I think that if i don't add the sort function into my mode function, once i have a list such as { 1,2,4,3,3,4}
then my mode will become 4 instead of 3
To make the function return all the modes, it will need to return an array (vector). You will need another for loop at the end of that function to put all modes into that array. Finally, you can use sort to make removing duplicates easier.