c++ - 无法将元素插入 unordered_set
问题描述
我正在开发一个使用无序集作为邻接集的图,并且在尝试将边插入邻接集时遇到了问题。问题是我编写的方法似乎没有将任何边插入顶点的邻接集中。
下面是我用来向顶点添加边的方法的代码。
addEdge
在hash-graph.hpp
/**
* 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);
}
addEdge
在顶点.hpp
template <class K, class V>
bool Vertex<K, V>::addEdge(Edge<K> edge)
{
if (this->hasEdge(edge))
return false;
adjacencySet.insert(edge);
return true;
}
谁能帮我解决这个问题?如果您想查看任何其他代码,请告诉我。
解决方案
推荐阅读
- assembly - 如何使用随机播放控制掩码
- nginx - Nginx - 在位置重写
- java - 如何在 JDK 10 中移动鼠标?.mousePress(InputEvent.BUTTON1_MASK); 不再工作
- python - 在 python 中使用正则表达式根据某些模式删除一些行
- python - rpy2 ggplot2 错误:输入无效:date_trans 仅适用于 Date 类的对象
- javascript - 如何修复使用 100% 宽度的 javascript 滑块中的疯狂间距?
- javascript - 两个显示/隐藏切换(如果单击 div 外部则隐藏)问题
- android - 在工具栏中添加三个点
- laravel-5 - 如何选择 created_at = 特定小时的记录?
- sql - 获取月份的名称 3 个月前