public EdgeWeightedDigraph(string fileName) { try { using (StreamReader streamReader = new StreamReader(fileName)) { _numberOfVertices = Convert.ToInt32(streamReader.ReadLine()); _numberOfEdges = Convert.ToInt32(streamReader.ReadLine()); InitializeGraph(_numberOfVertices, _numberOfEdges); string line; while ((line = streamReader.ReadLine()) != null) { var splittedLine = line.Split(' '); var edge = new DirectedWeightedEdge(Convert.ToInt32(splittedLine[0]), Convert.ToInt32(splittedLine[1]), Convert.ToDouble(splittedLine[2])); AddEdge(edge); } } } catch (Exception ex) { throw new InvalidOperationException(ex.Message); } }
public void AddEdge(DirectedWeightedEdge edge) { int u = edge.From(); adjList[u].AddFirst(edge); }