c++ - Trying to make adjacency list using link list and vectors -


i'm trying figure out how make adjacency list, having trouble understanding need do. have java code:

public class graph {  private final int v;  private bag<integer>[] adj;  public graph(int v) {  this.v = v;  adj = (bag<integer>[]) new bag[v];  (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);  } 

but i'm trying understand , convert c++. main part i'm unsure of

adj = (bag<integer>[]) new bag[v];  (int v = 0; v < v; v++)  adj[v] = new bag<integer>(); 

can transfer c++ please?

java:

adj = (bag<integer>[]) new bag[v];  (int v = 0; v < v; v++)  adj[v] = new bag<integer>(); 

c++:

vector<vector<int>> adj; for(int v=0;v<v;v++) adj.push_back(vector<int>()); 

java:

 public void addedge(int v, int w)  {  adj[v].add(w);  adj[w].add(v);  } 

c++:

public void addedge(int v, int w) {     adj[v].push_back(w);     adj[w].push_back(v); } 

one more thing: biginteger can store numbers larger int. it's not necessary use biginteger. because w , v in addedge must less v(v int) or overflow range of array.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -