类边缘列表C
class Edge List c++
我正在尝试在C 上进行边缘列表类。当我编译代码时,我会遇到很多错误,但是我听不懂,我错了?
struct vertex
{
double x,y;
};
class EdgeList
{
private:
std::map<vertex, vector<vertex>> graph_container;
public:
void add_vertex(const vertex& v) { //add a vertex to the map
graph_container.insert(pair<vertex,vector<vertex> >(v, vector<vertex>()));
}
//*
void add_edge(const vertex& v, const vertex& u) { //look up vertex in map
auto it = graph_container.find(v);
if (it != graph_container.end())
*it.push_back(u);
}
//*/
};
第一个错误是
64-w64-mingw32/include/c++/iostream:39,
from EarTr.cpp:1:
C:/mingw-w64/x86_64-5.2.0-win32-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/includ
e/c++/bits/stl_function.h:387:20: note: 'const vertex' is not derived from 'co
nst std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
{ return __x < __y; }
我已经在struct
中添加了2个功能bool operator==(const vertex &o)const {
return x == o.x && y == o.y;
}
bool operator<(const vertex &o) const{
return x < o.x || (x == o.x && y < o.y);
}
所以,现在地图可以与我的数据类型一起使用。我也使用
it->second.push_back(u);
而不是
*it.push_back(u);
相关文章:
- Pybind11:将元组列表从Python传递到C++
- 从链接列表c++中删除一个项目
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- C++如何通过用户输入删除列表元素
- 读取文件的最后一行并输入到链接列表时出错
- 复制列表初始化的隐式转换的等级是多少
- LNK2038、MSVS2017 MAGMA的原因列表
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 没有为自己的结构调用列表推回方法
- 使用简单类型列表实现的指数编译时间.为什么
- 一对向量构造函数:初始值设定项列表与显式构造
- 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- 通过for循环使用用户输入填充列表
- C++:如何使函数只返回作为列表一部分的字符串
- 概念中的cv限定符需要表达式参数列表
- 删除存储为邻接列表的图表中的边缘
- 如何将边缘列表转换为DCEL数据结构
- 类边缘列表C
- 如何从图形的邻接列表表示中随机选择边缘
- BGL:邻接列表为描述符返回错误的边缘属性