Example #1
0
        public static IDirectedGraph <int> ReverseGraph(IDirectedGraph <int> graph)
        {
            var reversedGraph = new DirectedGraphAdjList <int>(saveReversedVersion: false,
                                                               vertices: graph.GetVertices().ToArray());

            foreach (int v in graph.GetVertices())
            {
                foreach (int w in graph.GetAdjacentVertices(v))
                {
                    reversedGraph.AddEdge(w, v);
                }
            }

            return(reversedGraph);
        }