【发布时间】:2019-03-04 15:05:32
【问题描述】:
我有一个名为 Graph 的类。有这个顶点类的成员。我已经在构造函数中初始化了顶点。此外,还有一个向量成员数组。我希望向量的数量等于顶点。例如,如果 vertices = 5 那么我的向量数组应该是这样的。 向量 v[5]; 我如何在构造函数中执行此操作,因为我只会知道构造函数中顶点的值?
class Graph
{
private:
int vertices;
std::vector<int> adj[];
public:
Graph(int v); //constructor
// add an edge
void addEdge(int u, int v);
//print bfs traversal of graph
void bfs(int s); // s is a source from where bfs traversal should
//start
};
Graph :: Graph(int v)
{
vertices = v;
}
【问题讨论】: