【发布时间】:2021-07-18 12:29:28
【问题描述】:
所以这是我的函数,它基本上采用 2 个索引和 2D 数组并将权重添加到预期位置。
void AddEdge(int Vertex1Index, int Vertex2Index, int weight, int Edge)
{
if (Vertex1Index==-1 || Vertex2Index==-1) // in case of invalid vertex
{
return ;
}
Edge [Vertex1Index][Vertex2Index] = weight; //using indexes to enter weight
}
问题是我的大小是由用户在程序开始时定义的(需要这样做)否则我会将大小设为全局常量。
这就是你调用函数的方式
AddEdge(SearchVertex(Value, Size, Vertices),SearchVertex(Value1,Size, Vertices),weight, Graph);
搜索顶点搜索顶点数组中的输入并返回索引。如果顶点不存在,则返回 -1。
【问题讨论】:
-
你可以试试
boost multidimensional arrayboost.org/doc/libs/1_61_0/libs/multi_array/doc/user.html
标签: c++ pointers multidimensional-array