Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am stuck on the last two methods of this assignment. Any help is greatly appre

ID: 3540480 • Letter: I

Question

I am stuck on the last two methods of this assignment. Any help is greatly appreciated.  I need the below two methods called COMPRESS and DECOMPRESS to return the items indicated in their method headers.  If I have made an error anywhere else please let me know. Thank you.


import java.io.FileInputStream;
import java.util.*;


public class HuffmanTree {
    public HuffmanNode overallRoot;
    
    public HuffmanTree(Map<Character, Integer> counts) {
        PriorityQueue<HuffmanNode> pq = new PriorityQueue<HuffmanNode>();
        Set<Character> characters = counts.keySet();
        for (Character c : characters) {
          pq.add(new HuffmanNode(c, c.charValue()));
        }
        System.out.println(pq.toString());
    }
    
    public String printSideways() {
        return printSideways(overallRoot, 0);
    }
    
    private String printSideways(HuffmanNode root, int level) {
        String sideways = "";
        if (root != null) {
            printSideways(root.right, level + 1);
            for (int i = 0; i < level; i++) {
                sideways += ("    ");
            }
            sideways += (root.frequency);
            printSideways(root.left, level + 1);
        }
        return sideways;
    }

    public StringBuilder compress(FileInputStream inputFile) {
        // TODO Auto-generated method stub
        return null;
    }

    public String decompress(StringBuilder inputString) {
        // TODO Auto-generated method stub
        return null;
    }

}

Explanation / Answer

Here is my complete implementation. Do rate :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote