| | |
How do i calculate the frequency of elements in a chain node.
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2004
Posts: 11
Reputation:
Solved Threads: 0
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.
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
- Java Loan Application (Java)
- Help with simple Array program (Visual Basic 4 / 5 / 6)
- i need help...syntax error (C#)
- help me solve my matlab syntax error (Legacy and Other Languages)
- please help me solve my matlab prob (Computer Science)
- Heeeeeeeeeeeeeeeeelp pleeeaaazzzz :cry: :cry: :cry: (C)
Other Threads in the Java Forum
- Previous Thread: Question about Properties
- Next Thread: comparing two integers
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor





