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 data, Comparable count)
        {
                alphaRoot = insert(alphaRoot, data, count);
        }

        private Object sortOutput(alphaNode n, Comparable data, Comparable count)
        {
                if(n == null)
                {
                        return new alphaNode(data, count);
                }
                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.left, data, count);
                        }
                        //if there is no right child move right and call recursivly
                        else if(n.right == null)
                        {
                                n.right = sortOutput(n.right, data, count);
                        }
                        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.left, data, count);
                                else
                                        n.right = sortOutput(n.right, data, count);
                        }
                }
                //increment size counter and return n
                n.size++;
                return n;