public static Digraph <int> LoadGraph(string path) { var digraph = new Digraph <int>(); using (var file = new System.IO.StreamReader(path)) { // Number of nodes int size = int.Parse(file.ReadLine()); // Add nodes for (int i = 0; i < size; i++) { digraph.AddNode(new Node <int>(i)); } // Number of edges file.ReadLine(); string line; // Add edges while ((line = file.ReadLine()) != null) { var matches = Regex.Matches(line, @"\d+"); digraph.AddEdge(matches[0].Value, matches[1].Value); } } return(digraph); }
public override DigraphBase Reverse() { Digraph t = new Digraph(_vertice); for (int v = 0; v < _vertice; v++) { foreach (var temp in Adj(v)) { t.AddEdge(temp, v); } } return(t); }
public Digraph Reverse() { Digraph r = new Digraph(this.V); for (int v = 0; v < this.V; v++) { foreach (int w in this.GetAdjacencyList(v)) { r.AddEdge(w, v); } } return(r); }