Created
November 8, 2015 13:11
-
-
Save pimiento/b79a2d40960bdcd735b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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