本文整理汇总了C++中HuffmanTree::Encrypt方法的典型用法代码示例。如果您正苦于以下问题:C++ HuffmanTree::Encrypt方法的具体用法?C++ HuffmanTree::Encrypt怎么用?C++ HuffmanTree::Encrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HuffmanTree
的用法示例。
在下文中一共展示了HuffmanTree::Encrypt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: derp
int derp()
{
//testing huffmanqueue
cout << "what";
HuffmanQueue<HuffmanTreeNode, NodeComp> queue;
Huffman tm;
map<char, int> TextMap = tm.GetMap();
map<char, int>::iterator it = tm.GetIterator();
//priority_queue<HuffmanTreeNode*, deque<HuffmanTreeNode*>, NodeComp> queue;
HuffmanTreeNode *t;
for(it = TextMap.begin(); it!=TextMap.end(); it++)
{
t = new HuffmanTreeNode(it->first, it->second);
queue.push(t);
}
do
{
HuffmanTreeNode *temp;
HuffmanTreeNode * ref1 = queue.top();
queue.pop();
if(!queue.empty())
{
HuffmanTreeNode * ref2 = queue.top();
queue.pop();
temp = new HuffmanTreeNode(NULL, ref1->getFreq() + ref2->getFreq());
temp->SetLeftNode(ref1);
temp->SetRightNode(ref2);
}else
{
temp = new HuffmanTreeNode(NULL, ref1->getFreq());
temp->SetLeftNode(ref1);
temp->SetRightNode(NULL);
}
queue.push(temp);
}while(queue.size()!=1);
HuffmanTree* tree = new HuffmanTree(queue.top());
tree->BuildMap(queue.top());
//tree->GetChars(queue.top());
cout << "Printing Map \n";
tree->printMap();
string x = tree->Encrypt("go go gophers");
cout<<"Encrypting 'go go gophers' . :: "<<x<<endl<<endl;
tree->Compress(x);
cout<<"Decrypting '"<<x<<"' . :: "<<tree->Decrypt(x)<<endl;
system("pause");
return 0;
}