如果存在特定元素,则控制向量
Control a vector if there is a specific element
我正在尝试编写一种方法来控制向量,如果有特定元素。所以我有一个图结构,看起来像这样:
struct graph {
std::vector <std::vector<int>> gr;
};
然后我有一种在两个顶点之间添加边的方法。
void add_edge(graph& g, int from, int to) {
if ( from >= 0 && to >= 0 && from < g.gr.size() && to < g.gr.size()) {
g.gr[from].push_back(to);
}
}
此方法必须在两个顶点之间添加有向边,控制是否已经有有向边,如果是,则不执行任何操作。并且只能使用现有节点调用它。主要问题是我不知道如何控制是否有定向边缘。我尝试使用std::find(g.gr[from].begin,g.gr[from].end, to) != g.gr[from].end())
条件,但它以错误结束。
FIRST ERROR Severity Code Description Project File Line Suppression State Error C3867 'std::vector<int,std::allocator<_Ty>>::begin': non-standard syntax; use '&' to create a pointer to member DU2 c:users1...graph.hpp 81
SECOND ERROR Severity Code Description Project File Line Suppression State Error C2672 'std::find': no matching overloaded function found DU2 c:users1..graph.hpp 81
你忘记了g.gr[from].begin
末尾的()
,g.gr[from].end
std::find
相关文章:
- 写入向量<向量<bool>>
- 函数向量_指针有不同的原型,我可以构建一个吗
- std::向量与传递值的动态数组
- 将值指定给向量(2D)的向量中的某个位置
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 如何使用向量的template_back函数
- 尝试通过多个向量访问变量时,向量下标超出范围
- 如何通过派生类函数更改基类中的向量
- C++从另一个类访问公共静态向量的正确方法是什么
- 如何将ampl中的集合表示为c++中的向量
- 变量没有改变?通过向量的函数调用
- 迭代时从向量和内存中删除对象
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 计算排序向量的向量中唯一值的计数
- 矩阵向量乘法(cublasDgemv)返回零
- 一对向量构造函数:初始值设定项列表与显式构造
- 将结构向量排序为子组
- 如果存在特定元素,则控制向量
- 控制 std::向量重新分配