public LinkedList <IVertex <V> > Sort(IGraph <V, E> graph) { DFSTopoSortVisitor <V> dfsTopV = new DFSTopoSortVisitor <V>(); var edgeVisitor = new DummyEdgeVisitor <V, E>(); GraphSearch <V, E> graphSearch = new DepthFirstSearch <V, E>(); graphSearch.Search(graph, dfsTopV, edgeVisitor); return(dfsTopV.TopologicalSortedList); }
public int FindPartitions(IGraph <V, E> graph) { int partitions = 0; var search = new BreadthFirstSearch <V, E>(); var vertexVisitor = new DummyVertexVisitor <V>(); var edgeVisitor = new DummyEdgeVisitor <V, E>(); foreach (var vertex in graph.Vertices) { if (!search.IsVisited(vertex)) { partitions++; search.Search(graph, vertex, vertexVisitor, edgeVisitor); } } return(partitions); }