Tree: Huffman Decoding

  • + 0 comments

    JAVA

    void decode(String s, Node root) {        
        Node current = root;
        for (char c : s.toCharArray()) {           
            if (c == '0') {
                current = current.left;
            } else {
                current = current.right;
            }
            
            if (current != null && current.data != '\0') {
                System.out.print(current.data);
                current = root;
            }
            
        }
    }