本文整理汇总了C++中HuffmanTree::Decoding方法的典型用法代码示例。如果您正苦于以下问题:C++ HuffmanTree::Decoding方法的具体用法?C++ HuffmanTree::Decoding怎么用?C++ HuffmanTree::Decoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HuffmanTree
的用法示例。
在下文中一共展示了HuffmanTree::Decoding方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
string text;
bool BeingInit = 0, BeingEncode = 0;
HuffmanTree *tree;
char *c;
int *value;
int n;
int select;
while (true)
{
cout << "1.initialization" << endl;
cout << "2.write text to file" << endl;
cout << "3.Encoding" << endl;
cout << "4.Decoding" << endl;
cout << "5.Print CodeFile" << endl;
cout << "6.TreePrinting" << endl;
cout << "7.show The Huffman code" << endl;
cout << "8.exit" << endl;
cin >> select;
switch (select)
{
case 1:
int t;
cout << "1.build a new HuffmanTree" << endl;
cout << "2.load from the file" << endl;
cin >> t;
while (true)
{
if (t == 1)
{
cout << "输入字符个数:";
cin >> n;
c = new char[n];
value = new int[n];
for (int i = 0; i<n; i++)
{
cout << "第" << i + 1 << "个字符:";
cin >> c[i];
cout << "第" << i + 1 << "个权值:";
cin >> value[i];
}
tree = new HuffmanTree(value, n, c);
break;
}
if (t == 2)
{
tree = new HuffmanTree;
break;
}
}
cout << "initialization success!" << endl;
BeingInit = 1;
tree->save();
break;
case 2:cout << "input your text: "; cin >> text;
tree->writefile(text);
cout << "OK!" << endl;
break;
case 3:if (!BeingInit) { cout << "the tree is not exist" << endl; break; }
tree->Encoding();
cout << "succeed in encoding!" << endl;
BeingEncode = 1;
break;
case 4:if (!BeingInit) { cout << "the tree is not exist" << endl; break; }
if (!BeingEncode) { cout << "the tree haven't been encode, you must encoding before!" << endl; break; }
tree->Decoding();
cout << "succeed in decoding!" << endl;
break;
case 5:if (!BeingInit) { cout << "the tree is not exist" << endl; break; }
if (!BeingEncode) { cout << "the tree haven't been encode, you must encoding before!" << endl; break; }
tree->Print(); cout << endl; break;
case 6:if (!BeingInit) { cout << "the tree is not exist" << endl; break; }
tree->printing();
break;
case 7:tree->Huffmancode(); cout << endl; break;
case 8:exit(0);
default:break;
}
}