当前位置: 首页>>代码示例>>C++>>正文


C++ PriorityQueue::find方法代码示例

本文整理汇总了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;
    }
开发者ID:hutamaki,项目名称:cg,代码行数:22,代码来源:main.cpp

示例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;
}
开发者ID:anthonycj04,项目名称:Prim-s-Algo,代码行数:65,代码来源:prims.cpp


注:本文中的PriorityQueue::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。