private static void AddEdges(HouseConnection edge, List <HouseConnection> edges, List <HouseConnection> mpd, SortedSet <HouseConnection> priority, bool[] used) { for (int i = 0; i < edges.Count; i++) { if (!mpd.Contains(edges[i])) { if (edge.EndHouse == edges[i].StartHouse && !used[edges[i].EndHouse]) { priority.Add(edges[i]); } } } }
private static void FindMinimumSpanningTree(bool[] used, SortedSet <HouseConnection> priority, List <HouseConnection> mpdEdges, List <HouseConnection> edges) { while (priority.Count > 0) { HouseConnection edge = priority.Min; priority.Remove(edge); if (!used[edge.EndHouse]) { used[edge.EndHouse] = true; // we "visit" this node mpdEdges.Add(edge); AddEdges(edge, edges, mpdEdges, priority, used); } } }