函数代码:
void HuffTree::genHuffCode() // 为哈夫曼树中各叶子的字符生成哈夫曼编码
{
int start = MAX_CODE_LENGTH - 1;
for (int i = 1; i <= n; ++i)
{
int c = i;
int f = tree[c].parent;
while (f!=0)
{
if (tree[f].lchild == c)
{
tree[c].code[start] = '0';
}
else
{
tree[c].code[start] = '1';
}
c = f;
f = tree[c].parent;
--start;
}
for (int j = 0; j < MAX_CODE_LENGTH / 2; j++)
{
char t = tree[i].code[j];
tree[i].code[j] = tree[i].code[MAX_CODE_LENGTH - j - 1];
tree[i].code[MAX_CODE_LENGTH - j - 1] = t;
}
}
}
问题:
在f=tree[c].parent处异常终止
引发了异常: 读取访问权限冲突。
this 是 0x31A49F0A。