944,127 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4636
  • Java RSS
Feb 19th, 2005
0

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

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mus_203 is offline Offline
11 posts
since Sep 2004
Feb 19th, 2005
0

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

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....
Reputation Points: 25
Solved Threads: 11
Junior Poster
tonakai is offline Offline
121 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Question about Properties
Next Thread in Java Forum Timeline: comparing two integers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC