1
我想弄清楚如何使一个邻接列表,但无法理解我需要做什么。我有这个Java代码:试图使用链接列表和向量使邻接列表
public class Graph
{
private final int V;
private Bag<Integer>[] adj;
public Graph(int V)
{
this.V = V;
adj = (Bag<Integer>[]) new Bag[V];
for (int v = 0; v < V; v++)
adj[v] = new Bag<Integer>();
}
public void addEdge(int v, int w)
{
adj[v].add(w);
adj[w].add(v);
}
但我想了解它,并将其转换为C++。我不确定的主要部分是
adj = (Bag<Integer>[]) new Bag[V];
for (int v = 0; v < V; v++)
adj[v] = new Bag<Integer>();
任何人都可以帮助转移到C++吗?