Skip to content

Instantly share code, notes, and snippets.

@pimiento
Created November 8, 2015 13:11
Show Gist options
  • Select an option

  • Save pimiento/b79a2d40960bdcd735b3 to your computer and use it in GitHub Desktop.

Select an option

Save pimiento/b79a2d40960bdcd735b3 to your computer and use it in GitHub Desktop.
public class Graph {
private int V;
private int E;
private Bag<Integer>[] adj; // adjacency list
//create a V-vertex graph with no edges
public void Graph(int V) {
this.V = V;
this.E = 0;
adj = (Bag<Integer>[])new Bag[V];
for (int v = 0; v < V; v++)
adj[v] = new Bag<Integer>();
}
//read a graph from input stream in
public void Graph(In in) {
this(in.readInt());
int E = in.readInt();
for (int e = 0; e < E; e++) {
int v = in.readInt();
int w = in.readInt();
addEdge(v, w);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment