Tree: Huffman Decoding

  • + 0 comments
    def decodeHuff(root, s):
        curr_node = root
        for bit in s:
            if bit == '1':
                curr_node = curr_node.right
            elif bit == '0':
                curr_node = curr_node.left
            if not curr_node.right and not curr_node.left:
                print(curr_node.data, end='')
                curr_node = root