public void Compute() { // clear previous results SpanningTreeEdges.Clear(); // create disjoint set object // fill in disjoint sets DisjointSet dset = new DisjointSet(VisitedGraph.Vertices); // create and fill in priority queue PriorityQueue Q = new PriorityQueue(Weights, VisitedGraph.Edges); // iterate over edges while (Q.Count != 0) { IEdge e = Q.Peek(); Q.Pop(); IVertex u = dset.FindSet(e.Source); IVertex v = dset.FindSet(e.Target); if (u != v) { SpanningTreeEdges.Add(e); dset.Link(u, v); } } }
private void DepthFirstSearch(INode startNode, IVisitor visitor) { _dfsStack.Push(startNode); visitor.Visit(startNode); ((Node)startNode).Visited = true; foreach (IEdge edge in startNode.Edges) { INode to = edge.To; if (!((Node)to).Visited && !_dfsStack.Contains(to)) { visitor.Visit(to); if (_span) { SpanningTreeEdges.Add(edge); } ((Node)to).Visited = true; DepthFirstSearch(to, visitor); } } _dfsStack.Pop(); }