public List <T> GetAll() { List <T> ret = new List <T>(); while (m_minPQ.Size() != 0) { ret.Add(m_minPQ.DeleteTop()); } ret.Reverse(); return(ret); }
public KruskaMST(EdgeWeightedGraph g) { m_mst = new Queue <Edge>(); MinPQ <Edge> pq = new MinPQ <Edge>(g.Edges()); UnionFind uf = new UnionFind(g.V()); while (!pq.IsEmpty() && m_mst.Count < g.V() - 1) { Edge e = pq.DeleteTop(); int v = e.Either(); int w = e.Other(v); if (uf.Connected(v, w)) { continue; } uf.Union(v, w); m_mst.Enqueue(e); } }