From e3c487f39f44cdecb514fd33e0f5d3f4465451b2 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Thu, 22 Apr 2021 01:08:21 -0500 Subject: added more generics --- IO/GraphFile.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'IO') diff --git a/IO/GraphFile.cs b/IO/GraphFile.cs index 42a1b2b..2e00eef 100644 --- a/IO/GraphFile.cs +++ b/IO/GraphFile.cs @@ -3,13 +3,15 @@ using Interfaces; namespace Graph.IO { + using Graph = Graph, double>, Edge, double>; + public static class GraphFile { // read a graph from file using IFileReader (i.e. Dependancy injection for unit testing) - public static Graph Read(IFileReader reader) + public static Graph Read(IFileReader reader) { string[] lines = reader.Lines; - Graph graph = new Graph(); + Graph graph = new Graph(); foreach (string line in reader.Lines) { @@ -42,11 +44,11 @@ namespace Graph.IO } // write a graph to file using IFileWriter (i.e. Dependancy injection for unit testing) - public static void Print(Graph graph, IFileWriter writer) + public static void Print(Graph graph, IFileWriter writer) { // create array of strings with a size equal to vertices string[] lines = new string[graph.Vertices.Count]; - + // add each vertex to it's parents output line graph.Vertices.ForEach(vertex => { @@ -57,7 +59,7 @@ namespace Graph.IO // for vertex & parent, create string if not already lines[vertex.Id] ??= $"{vertex.Id}"; lines[vertex.Parent] ??= $"{vertex.Parent}"; - + // add vertex + weight to parent's string & visa versa lines[vertex.Parent] += $" {vertex.Id} {vertex.Key.ToString("F1")}"; lines[vertex.Id] += $" {vertex.Parent} {vertex.Key.ToString("F1")}"; -- cgit v1.2.3-70-g09d2