我正在尝试制作一个霍夫曼树程序,以便将给定的哈希转换为霍夫曼树。我想返回一个元组列表,每个元组都有子元素、频率、父元素和赋值 0 0r 1。
但是当我运行代码时,它显示了太多需要解包的值。你能验证我的代码吗?
temp_var = -1
new_heap = []
stack_heap = []
ref_hash = freq_table.copy()
len_freqtable = len(freq_table)
while(len_freqtable > 1):
new_heap.append(pop(freq_table))
new_heap.append(pop(freq_table))
pop_first = new_heap.pop(0)
freq_first = ref_hash[pop_first]
pop_second = new_heap.pop(0)
freq_second = ref_hash[pop_second]
append_composite = pop_first + pop_second
stack_heap.append((pop_first,freq_first,append_composite,'0'))
stack_heap.append((pop_second,freq_second,append_composite,'1'))
freq_table[append_composite] = freq_first + freq_second
ref_hash[append_composite] = freq_first + freq_second
len_freqtable = len_freqtable - 1
temp_var = temp_var - 1
return stack_heap