本文整理汇总了C++中PriorityQueue::find方法的典型用法代码示例。如果您正苦于以下问题:C++ PriorityQueue::find方法的具体用法?C++ PriorityQueue::find怎么用?C++ PriorityQueue::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue::find方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isWorthTrying
bool isWorthTrying(Node<Plot>* node, PriorityQueue& pqueue, std::unordered_map<Plot*, int>& closeList)
{
auto found(pqueue.find(node));
if (found != pqueue.end())
{
if ((*found)->f < node->f) return false;
else
{
Node<Plot>* n(*found);
pqueue.erase(found);
delete n;
}
}
auto cl_found(closeList.find(node->node));
if (cl_found != closeList.end())
{
if (cl_found->second < node->f) return false;
else closeList.erase(cl_found);
}
return true;
}
示例2: prim
void prim(Graph graph, char startNode){
PriorityQueue priorityQueue;
Node node;
node.key = INT_MAX;
node.pi = '\0';
// for (auto it = graph.getVertices().begin(); it != graph.getVertices().end(); it++){
// node.name = *it;
// priorityQueue.push(node);
// }
string tempString = "";
for (auto it = graph.getVertices().begin(); it != graph.getVertices().end(); it++)
tempString += *it;
cout << tempString << "!!!" << endl;
for (int i = 0; i < tempString.length(); i++){
node.name = tempString.c_str()[i];
priorityQueue.push(node);
}
// Node node;
// node.key = INT_MAX;
// node.pi = '\0';
// node.name = 'i';
// priorityQueue.push(node);
// node.name = 'a';
// priorityQueue.push(node);
// node.name = 'b';
// priorityQueue.push(node);
// node.name = 'c';
// priorityQueue.push(node);
// node.name = 'd';
// priorityQueue.push(node);
// node.name = 'e';
// priorityQueue.push(node);
// node.name = 'f';
// priorityQueue.push(node);
// node.name = 'g';
// priorityQueue.push(node);
// node.name = 'h';
// priorityQueue.push(node);
cout << "finished inserting vertices" << endl;
priorityQueue.decreaseKey(startNode, 0, '\0');
while (!priorityQueue.empty()){
Node node = priorityQueue.extractMin();
cout << "extracted: " << node.name << ": " << node.key << ", " << node.pi << endl;
if (node.name != node.pi && node.pi != '\0')
cout << "(" << node.name << ", " << node.pi << ") " << endl;
for (auto it = graph.getEdges().begin(); it != graph.getEdges().end(); it++){
cout << "checking " << it->first << endl;
if (it->first.c_str()[0] == node.name || it->first.c_str()[1] == node.name){// Adjacency
char adjacency = (it->first.c_str()[0] == node.name)?it->first.c_str()[1]:it->first.c_str()[0];
cout << "going for adj" << adjacency << endl;
if (priorityQueue.find(adjacency) && priorityQueue.getNode(adjacency).key > graph.getWeight(node.name, adjacency)){
cout << "decreasingKey: " << adjacency << ", w: " << graph.getWeight(node.name, adjacency) << ", " << node.name << endl;
priorityQueue.decreaseKey(adjacency, graph.getWeight(node.name, adjacency), node.name);
}
}
}
}
cout << endl;
}