954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do i calculate the frequency of elements in a chain node.

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.

mus_203
Newbie Poster
11 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

well easiest implementation is,first assinging a counter for each possible array elements (in this case an array of 10 elements) then looking at each element of the array and increase this element's counter by 1. then output the counters....

tonakai
Junior Poster
121 posts since Feb 2005
Reputation Points: 25
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You