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

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2004
Posts: 11
Reputation: mus_203 is an unknown quantity at this point 
Solved Threads: 0
mus_203 mus_203 is offline Offline
Newbie Poster

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

 
0
  #1
Feb 19th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 121
Reputation: tonakai is an unknown quantity at this point 
Solved Threads: 11
tonakai's Avatar
tonakai tonakai is offline Offline
Junior Poster

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

 
0
  #2
Feb 19th, 2005
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....
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC