本文整理汇总了C++中HuffmanTree::buildNodeList方法的典型用法代码示例。如果您正苦于以下问题:C++ HuffmanTree::buildNodeList方法的具体用法?C++ HuffmanTree::buildNodeList怎么用?C++ HuffmanTree::buildNodeList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HuffmanTree
的用法示例。
在下文中一共展示了HuffmanTree::buildNodeList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildNodeList
void UncompressFile::buildNodeList(HuffmanTree& ht)
{
if ( !isPtr.is_open()) {
isPtr.open(inFile.c_str());
if (!isPtr) {
cerr << "Error: Could not open: '" << inFile << "' for reading" << endl;
return;
}
}
// char readBuf[readBufSize];
isPtr.getline((char*)readBuf,readBufSize);
string buf; // Have a buffer string
vector<string> token;
stringstream ss((char*)readBuf);
unsigned int count;
// Tokenize the string into a vector
while (ss >> buf) {
token.push_back(buf);
count++;
}
// Validate that we have a even number
if (count % 2 != 0) {
cerr << "CountTable::extractCharMap() : Internal Error\n";
return;
}
unsigned int c;
// Convert the first token to 'hex' and the second to 'unsigned'
for (unsigned i=0; i<token.size(); i+=2) {
istringstream hex_char(token[i]);
hex_char >> hex >> c;
istringstream int_char(token[i+1]);
int_char >> count;
ht.buildNodeList(c, count);
}
if (isPtr.is_open()) isPtr.close();
} // End buildNodeList()