流程图3
2019-12-23 22:43:41 13 举报
流程图
作者其他创作
大纲/内容
否
a.next.val = 1a.next.piror = aa = a.next
i=1
是
i=i+1
打印对字母
if (i.next!=None)
if (start.lchild == 0)
if ( i < n)
i=0输入每个字母的权重计算字母个数n初始化哈夫曼数组ht[2*n]数组每个结点的各个数值赋值为0ht[i].weight = 0ht[i].parent = 0ht[i].lchild = 0ht[i].rchild = 0
输入需要解码的字符串num计算长度nstart=ht[2*n-1]i=0
m1 = m2 = min1 = min2 = float('inf') j=1#m1 m2 为结点序号,min1 min2 为最小结点的权重,都设置为最大值
if (i == '0')
if ( i <=2*n)
if (ht[f].lchild==c)
if ( j<i)
start = self.ht[2*n-1]i=i+1
if(min2 > ht[j].weight)
a.next.val = 0a.next.piror = aa = a.next
解码
打印哈夫曼表
if ( i<=n)
创建编码数组mima[n+1]初始化每个结点链表为mima[i].val= Nonemima[i].next= Nonemima[i].piror= Nonei=1
找权重最小的两个结点并且构建哈夫曼表
开始编码
开始
if (i<=2*n-1)
结束
i = i.next
min2 = min1m2 = m1min1 = ht[j].weightm1 = j
ht[m1].parent = i ht[m2].parent = iht[i].weight = ht[m1].weight + self.ht[m2].weight ht[i].lchild = m1ht[i].rchild = m2
if( ht[j].parent == 0)
打印i.val i = i.piror
a = start.lchild
if ( f != 0)
给哈夫曼数组ht每个结点权重赋值ht[i].weight=weight
if (i == '1')
if (i.piror!=None)
j=1
if (j<=n)
if(min1 > ht[j].weight)
j=j+1
c = f f = ht[f].parent
i = mima[j]
c = i f = ht[i].parenta = mima[i]
a = start.rchild
min2 = ht[j].weightm2 = j
0 条评论
下一页