无法将元素插入unordered_set

时间:2019-02-21 15:11:14

标签: c++

我正在开发一个使用无序集作为邻接集的图,并且在尝试将边缘插入邻接集时遇到了问题。问题在于,我编写的方法似乎没有将任何边插入顶点的邻接集中。

下面是我用来向顶点添加边的方法的代码。

hash-graph.hpp

中的

addEdge

/**
 * Adds a non-existent, directed, edge from a "tail vertex" to a 
 * "head vertex" by modifying the adjacency set of the "tail vertex".
 * If the passed in edge already exists, the method instead returns
 * false.
 * 
 * @param   tail  the vertex at which the edge starts
 * @param   head  the vertex at which the edge ends
 * @return  false if edge already exists, else true
*/ 
template <class K, class V>
bool HashGraph<K, V>::addEdge(K tail, K head)
{
   Vertex<K, V> vTail = getVertex(tail);
   Edge<K> edge(head);
   return vTail.addEdge(edge);
}
vertex.hpp

中的

addEdge

template <class K, class V>
bool Vertex<K, V>::addEdge(Edge<K> edge)
{
    if (this->hasEdge(edge))
        return false;
    adjacencySet.insert(edge);
   return true;
}

有人可以帮助我解决此问题吗?如果您想查看其他代码,请告诉我。

0 个答案:

没有答案
相关问题