Finding mode in an array

I have to use numbers in my .txt file that are stored in an array. So i have to write a function to find the mode of the numbers in my array. What is a code that will do this, i have searched forums and cant find anything that does this
What would be the point of the assignment if you didn't come up with the solution yourself?

All you need to know is what the mode is and a little bit of programming and you can solve the problem.

Last edited on
Well I am not asking for the whole part I just need an idea of how to start it, I have checked my text book and as I said the Internet but I just can't think of a way to do this
One way to do it involves first sorting the elements.

Another way that works nicely requires counting the elements using a separate array where the indexes correspond to the values of the other array, and the values correspond to the number of occurrences, but this is only a good option if you are guaranteed a fairly small range of values in the array.

Other ways might involve using special data structures.
Last edited on
Another way that works nicely requires counting the elements using a separate array where the indexes correspond to the values of the other array, and the values correspond to the number of occurrences

I'm probably out of place saying this, but std::map can use ints as keys, avoiding the waste of space of using an array if the values are not very small.
Thanks for the help guys, I didn't figure out how to get this set up as the program was due at 11:00 last night but I have class today and am going to stay after and talk to my teacher about it.
Topic archived. No new replies allowed.