Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-08-2008, 12:50 AM
Member
 
Join Date: May 2008
Posts: 2
justlearning is on a distinguished road
Frequency Counter
I am working on a project and am having difficulty figuring out how to approach this problem. These are my instructions: "The output is sorted alphabetically by word. Instead, you will be sorting by count. Create a new private object class in your FrequencyCounter class that stores word, and count, and is comparable by count, then by word. Upon calling display(), the data should be put in the new private object and inserted into a max-heap. Remove in-order and output from there. The bar graph will show the most frequently used words first."

I have already created the program which sorts alphabetically. I am now trying to sort by frequency. What i have for the methods so far is below. Any suggestions would be appreciated.

PHP Code:
private Object sortOutput(Comparable dataComparable count)
        {
                
alphaRoot insert(alphaRootdatacount);
        }

        private 
Object sortOutput(alphaNode nComparable dataComparable count)
        {
                if(
== null)
                {
                        return new 
alphaNode(datacount);
                }
                else
                {
                        
//if the count is larger than the current nodes count swap
                        
if(count.compareTo(n.count)>= 0)
                        {
                                
Comparable temp data;
                                
data n.data;
                                
n.data temp;
                        }
                        
//if there is no left child move left and call recursivly
                        
if(n.left == null)
                        {
                                
n.left sortOutput(n.leftdatacount);
                        }
                        
//if there is no right child move right and call recursivly
                        
else if(n.right == null)
                        {
                                
n.right sortOutput(n.rightdatacount);
                        }
                        else
                        {
                                
//If the left side is larger than the right side move left; else move right
                                
if(n.left.size <= n.right.size)
                                        
n.left sortOutput(n.leftdatacount);
                                else
                                        
n.right sortOutput(n.rightdatacount);
                        }
                }
                
//increment size counter and return n
                
n.size++;
                return 
n
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] BST Frequency Counter theonly Advanced Java 7 04-30-2008 01:33 AM
Help with static variable counter silvia New To Java 1 07-19-2007 09:53 PM


All times are GMT +3. The time now is 01:11 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org