public EdgeWeightedGraph(EdgeWeightedGraph G) { //this(G.V()); int V = G.V(); if (V < 0) { throw new System.Exception("Number of vertices must be nonnegative"); } this.v = V; this.e = 0; adj = new Bag <Edge> [V]; for (int v = 0; v < V; v++) { adj[v] = new Bag <Edge>(); } this.e = G.E(); print(G.V()); for (int v = 0; v < G.V(); v++) { // reverse so that adjacency list is in same order as original Stack <Edge> reverse = new Stack <Edge>(); foreach (Edge e in G.adj[v]) { reverse.push(e); } foreach (Edge e in reverse) { adj[v].Add(e); } } }
public EagerPrimMST(EdgeWeightedGraph g) { _edgeTo = new Edge[g.V()]; _distTo = new double[g.V()]; for (var i = 0; i < g.V(); i++) { _distTo[i] = double.PositiveInfinity; } _marked = new bool[g.V()]; _pq = new MinPQ <double>(g.E()); Visit(g, 0); }