public PrimMST(WeightedGraph graph) { List <Edge> edges = new List <Edge>(); this.graph = graph; queue = new MinHeap <Edge>(graph.V()); visited = new bool[graph.V()]; visit(0); while (!queue.isEmpty()) { Edge min = queue.Popup(); edges.Add(min); wt += min.Weight(); visit(min.To()); } this.edges = edges.ToArray <Edge>(); }
public LazyPrimMST(WeightedGraph graph) { this.graph = graph; this.heap = new MinHeap <Edge>(graph.E()); List <Edge> edges = new List <Edge>(); visited = new bool[graph.V()]; visit(0); while (!heap.isEmpty()) { Edge min = heap.Popup(); if (visited[min.To()]) { continue; } wt = wt + min.Weight(); edges.Add(min); visit(min.To()); } this.edges = edges.ToArray <Edge>(); }