Tree: Huffman Decoding

  • + 1 comment

    Notice: In python, The null of node data judgement condition should be "\0" rather than "", " " or None.('\0' is treated simply as a character within a string.)

    def decodeHuff(root, s):
        pointer = root
        decode_s = ""
        for c in s:
            if c=="1":
                pointer=pointer.right
            else:
                pointer = pointer.left
            if pointer.data!='\0':
                decode_s += pointer.data
                pointer = root
        print(decode_s)