static ICollection<Node> PrimAlgorithm(Node startNode) { var mst = new List<Node>(); PriorityQueue queue = new PriorityQueue(); startNode.Used = true; mst.Add(startNode); foreach (var connection in neighbourhood[startNode]) { queue.Enqueue(connection); } while (mst.Count != houses.Count) { var current = queue.Dequeue(); current.ToNode.Used = true; mst.Add(current.ToNode); foreach (var connection in neighbourhood[current.ToNode]) { if (!connection.ToNode.Used) { queue.Enqueue(connection); } } } return mst; }
public Connection(Node to, int dist) { this.ToNode = to; this.Distance = dist; }