psdakpad
This commit is contained in:
parent
a472ce155c
commit
aae24036d0
@ -32,4 +32,14 @@ class HuffmanTree:
|
||||
# zoznam listov
|
||||
nodes = []
|
||||
for ch in freq:
|
||||
nodes.append(HuffmanNode(ch, freq[ch]))
|
||||
nodes.append(HuffmanNode(ch, freq[ch]))
|
||||
# spajame dva uzly s najmensou frekvenciou
|
||||
while len(nodes) > 1:
|
||||
nodes.sort(key=lambda x: x.frequency)
|
||||
left = nodes.pop(0)
|
||||
right = nodes.pop(0)
|
||||
parent = HuffmanNode(None, left.frequency + right.frequency, left, right)
|
||||
nodes.append(parent)
|
||||
|
||||
self.root = nodes[0]
|
||||
self.make_codes(self.root, "")
|
||||
Loading…
Reference in New Issue
Block a user