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 :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.