423,485 Members | 1,664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,485 IT Pros & Developers. It's quick & easy.

function pointers

P: 4
how do you find the most frequent number in an array and count how many times it has occured using pointers?
1 Week Ago #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,180
I would use mapping arrays.

One array for the values and a second array for the number of occurrences.


Initialize the values array with a number for each element that means "not used".

Initialize the values array setting each element to 0.

The you march down to your test array once.

For each element in the test array, look up the element value in your values array. If it's not there then put the value in one of the "not used" elements.


Add 1 to the number of occurrences for that value.


Remember, the third element in your values array uses the third total in your occurrences array.

At end of your pass of the test array, all the values and occurrences are in your mapping arrays.

Now just look for the largest number in your occurrences array. When you find it, the number it represents will be at the same position in your values array.
6 Days Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.