我正在尝试制作一个哈夫曼树程序,以便它将给定的哈希转换为哈夫曼树。我想返回一个元组列表,每个元组都有子元素、它的频率、父元素和一个赋值0或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
你肯定会做这样的事
检查函数的所有返回值,并查看返回的元素数是否如预期的那样。在
相关问题 更多 >
编程相关推荐