I have to write a C++ code that finds the mode of an array. I'm told that it's much easier to find the mode of an array AFTER the numbers have been sorted. I sorted the function but still cannot find the mode.
The mode is the number that is repeated more often than any other
If you have a sorted array, then it is easy to count how many times a value occurs. As you progress through values (and the array), you keep track of the most repeated value so far and its count. If a new value is more frequent, then you update the tracking data.
PS. It is possible to have multi-modal data; more than one distinct value repeats many times.