Hi I need help with devising a method that will calculate the frequency of elements in a chain data structure.
Here's an example of what the method is supposed to do.
If x = [3,6, 5, 9, 4, 5, 3, 5, 5, 1, 6, 10, 3, 3, 1, 7, 5, 1, 4, 1, 5, 5, 1, 3, 9, 8, 8, 8, 6, 7, 7, 7, 10, 7, 5, 2, 5, 9, 4, 2],
The method should generate the following output
element frequency
======= =====================
1 5 55555 ( 13%)
2 2 22 ( 5%)
3 5 55555 ( 13%)
4 3 333 ( 8%)
5 9 999999999 ( 23%)
6 3 333 ( 8%)
7 5 55555 ( 13%)
8 3 333 ( 8%)
9 3 333 ( 8%)
10 2 22 ( 5%)
======= =====================
40 (100%)
I was thinking of using a for loop to compare the first node, with the other nodes ie chainNode.next and by using the get method of the chain class to return each matching element. But I'm sure that this is a tedious method and secondly it probably won't work.
If anyone can be of any help I will be very grateful.
Mus.