C++实现Huffman树(二)

2014-11-24 09:39:06 · 作者: · 浏览: 1
ew int[nLeafCount]; //保存权值
for (i=0; i {
cout<<"Input letter and weight"< cin>>pLetter[i]>>pWeight[i];
}

HuffmanTree HT = NULL;
HuffmanCode HC = NULL;
HuffmanCoding(HT, HC, pWeight, nLeafCount); //调用方法,建立Huffman树,并获取编码序列

for (int i=1; i<=nLeafCount; ++i) //输出叶子节点的编码
{
cout< }

system("pause");

if (HT) //释放树资源
{
delete [] HT;
HT = NULL;
}

for (int i=1; i<=nLeafCount; ++i) //释放存放编码的资源
{
delete [] HC[i];
HC[i] = NULL;
}

if (HC)
{
delete [] HC;
HC = NULL;
}

if (pLetter)
{
delete [] pLetter;
pLetter = NULL;
}
if (pWeight)
{
delete [] pWeight;
pWeight = NULL;
}

return 0;
}