package huffman; public class Node { Node left,right; // node children in a tree int freq; // frequency of nodes in the subtree rooted at this node int value; // if leaf, byte represented by this node public Node(Node leftNode, Node rightNode, int frequency, int v){ left = leftNode; right = rightNode; freq = frequency; value = v; } public boolean isLeaf(){ // if left is null, right is null also, so don't need to check right return (left == null); } public String contents(){ if (isLeaf()) return "leaf "+String.format("0x%02X", value)+" "+freq+" "+(char) (value & 0xFF); else return "node "+Integer.toString(freq); } public void printTree(int indent) { for (int i = 0; i < indent; i++) { System.out.print(" "); } System.out.println(contents()); //System.out.println(String.format("%.4f", freq)); //System.out.println(String.format("0x%02X", b)); if (!isLeaf()) { left.printTree(indent + 2); right.printTree(indent + 2); } } }