【发布时间】:2013-11-02 01:33:24
【问题描述】:
在获取地图键方面有点挣扎。我想要这个方法来修改一个边向量,其中索引是目标节点,该索引的值是权重。向量“edges”已经初始化足够大以容纳边缘。编译器抱怨它无法将迭代器类型转换为 int。如果可能的话,有人对如何处理这种转换有任何建议或想法吗?谢谢。这是我正在实施 Dijkstra 的 MOOC 最短路径的任务的一部分。
void CompleteGraph::GetNodeEdges(int Node, std::vector<int> &edges){
// Modifies a vector of edges given the source node sorted by edge weight
// Iterate over a map. Grab all edges that have the given start node(map's 1st key)
typedef std::map<int, std::map<int, int> >::iterator iter;
for(iter i = Graph.begin(); i != Graph.end(); i++){
if (i->first == Node){
edges[i->second.begin()] = i->second.end();
}
}
// Sort vector here: will do this next
}
【问题讨论】:
标签: c++11 vector iterator stdmap