I have an int array:
{1,2,4,2,3,5,6,4,3}
How can I find frequencies of array elements like 1=1,2=2,3=2,4=4... I need a class which I can pass my array to and return an array which gives the count of array elements. ex:- array{[0]=1,[1]=2,[2]=3,[3]=4..} (for above example array);
解决方案
You have to do a few things:
Define an upper and lower bound for your range of numbers.
Establish a convenient object/data structure to store occurrences of these numbers.
Iterate through the passed-in array and count all occurrences of each number, storing the result in the convenient object/data structure.
If this is done in a simple manner, it could be only a matter of reading the elements from the passed-in array and printing out the final result.