Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-01-2012, 06:10 AM   PM User | #1
ageniu1st
New to the CF scene

 
Join Date: May 2012
Location: USA
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ageniu1st is an unknown quantity at this point
Traverse Binary Tree and build Hashmap

I need to create a Hashmap that keeps track of the frequency of words in a BinarySearchTree.
How do i integrate the two to let the Hashmap know that its arguments are in the Tree?
Say my map is as follows:

Code:
// Initialize frequency table from command line
for (String a : args) {
Integer freq = m.get(a);
m.put(a, (freq == null) ? 1 : freq + 1);
}

System.out.println(m.size() + " distinct words:");
System.out.println(m);
Explanations of your methods are especially helpful.
ageniu1st is offline   Reply With Quote
Old 05-01-2012, 03:25 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You would use a Map<Object, Integer> datatype. The key is the object in question, and the value is the number of occurrences. Can be stored in a custom tree to internally keep track of the count. Alternatives include using two other collections to contain the object as well as the occurrences.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
map, tree

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:35 PM.


Advertisement
Log in to turn off these ads.