You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def getHuffmanTree(txt):
if len(txt) == 0:
return
freq = {ch: txt.count(ch) for ch in set(txt)}
pq = [Node(k, v) for k, v in freq.items()]
hpf(pq)
while len(pq) > 1:
left, right = hpp(pq), hpp(pq)
newFreq = left.freq + right.freq
hppu(pq, Node(None, newFreq, left, right))
root = pq[0]
return root
def printTree(node, level=0, prefix=''):
if node is not None:
print(' ' * level + prefix + str(node.freq))
if node.left is not None or node.right is not None:
printTree(node.left, level + 1)
printTree(node.right, level + 1)
huffmantree.py has many syntax and logical error, I suggest to remove the file.
Does someone think the same thing?
The text was updated successfully, but these errors were encountered: