src/main/java/com/jmsoftware/datastructuresandalgorithms/huffman/entity/HuffmanTree.java
/**
     * Recursive function to print the huffman-code through the tree traversal.
     * Here s is the huffman - code generated.
     *
     * @param rootNode the root
     * @param string   the string
     */
Recursive function to print the huffman-code through the tree traversal.
Here s is the huffman - code generated.

@param rootNode the root
@param string   the string
Recursive function to print the huffman - code through the tree traversal . Here s is the huffman - code generated . @param rootNode the root @param string the string
public static void recursivePrintHuffmanCode(HuffmanNode rootNode, String string) {
        if (rootNode == null) {
            return;
        }
        if (rootNode.isLeaf()) {
            System.out.println(rootNode.getCharacter() + ":" + string);
            return;
        }
        recursivePrintHuffmanCode((HuffmanNode) rootNode.getLeftChildNode(), string + "0");
        recursivePrintHuffmanCode((HuffmanNode) rootNode.getRightChildNode(), string + "1");
    }
public static void recursivePrintHuffmanCode ( HuffmanNode rootNode , String string ) { if ( rootNode == null ) { return ; } if ( rootNode . isLeaf ( ) ) { System . out . println ( rootNode . getCharacter ( ) + ":" + string ) ; return ; } recursivePrintHuffmanCode ( ( HuffmanNode ) rootNode . getLeftChildNode ( ) , string + "0" ) ; recursivePrintHuffmanCode ( ( HuffmanNode ) rootNode . getRightChildNode ( ) , string + "1" ) ; }
Recursive function to print the huffman-code through the tree traversal.
Recursive function to print the huffman - code through the tree traversal .
// base case; if the left and right are null // then its a leaf node and we print // the code s generated by traversing the tree. // c is the character in the node // if we go to left then add "0" to the code. // if we go to the right add "1" to the code. // recursive calls for left and // right sub-tree of the generated tree.