0

I have aList< List< int> > graph; I have used it for representing an undirected graph. When i add a new edge graph[u].Add[v];, I am unable to itertate for a specific graph[u].

js-ninja
  • 3
  • 1

1 Answers1

1

Since your graph is undirected, you probably want to indicate both that u is connected to v and that v is connected to u.

graph[u].Add(v);
graph[v].Add(u);

Then you can see the nodes connected to u by iterating graph[u].