Tree: Huffman Decoding

  • + 2 comments

    Almost the same as my code.

    void decode(String encoding, Node root) {
        StringBuilder result = new StringBuilder();
        Node curr = root;
        for (char ch: encoding.toCharArray()) {
            curr = ch == '0' ? curr.left : curr.right;
            if (curr.data != '\0') {
                result.append(curr.data);
                curr = root;
            } 
        }
        System.out.println(result);
    }