本文整理汇总了C++中PQueue::add方法的典型用法代码示例。如果您正苦于以下问题:C++ PQueue::add方法的具体用法?C++ PQueue::add怎么用?C++ PQueue::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PQueue
的用法示例。
在下文中一共展示了PQueue::add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testPQueue
void testPQueue(PQueue& pq){
for(int i = 9 ; i > 0; i--){
pq.add(i);
}
// pq.add(1);
pq.removeAll();
}
示例2: buildEncodingForInput
void Encoding::buildEncodingForInput(ibstream& infile){
map<int, int> charMap;
getCharCount(infile, charMap);
PQueue<node*> pq;
map<int, int>::iterator iter;
for (iter = charMap.begin(); iter != charMap.end(); iter++){
node* tempNode = new node;
tempNode->letter = iter->first;
tempNode->weight = iter->second;
tempNode->leftChild = tempNode->rightChild = NULL;
//cout << tempNode->letter << endl;
pq.add(tempNode, iter->second);
}
map <int, string> encodingMap;
while (pq.size() != 1){
node *parent = new node;
parent->letter = 26;
parent->weight = 0; //probably don't need this
parent->leftChild = pq.extractMin();
parent->leftChild->path +='0';
parent->rightChild = pq.extractMin();
parent->rightChild->path += '1';
parent->weight = parent->leftChild->weight+parent->rightChild->weight;
pq.add(parent, parent->weight);
}
//for testing
map<int, int>::iterator it;
node* tree = pq.extractMin();
for (it = charMap.begin(); it != charMap.end(); it++){
BuildEncodingMap(tree, mp[it->first], it->first);
string temps = mp[it->first];
char tempc = it->first;
//cout << tempc << " has the encoding " << temps << endl;
}
//PrintTree(tree);
}