diff options
author | Toby Vincent <tobyv13@gmail.com> | 2021-04-20 00:50:28 +0000 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2021-04-20 00:50:28 +0000 |
commit | 1983882323827c48e5f8dd714d38319f35bb0cc3 (patch) | |
tree | c9454031cee5c5427d77c934aaa638adae8ac840 | |
parent | 8e30c07fb51de958d549a1d243345ce43cbe842c (diff) |
changed default parent value from null to -1
-rw-r--r-- | IO/GraphFile.cs | 11 | ||||
-rw-r--r-- | Vertex.cs | 2 |
2 files changed, 5 insertions, 8 deletions
diff --git a/IO/GraphFile.cs b/IO/GraphFile.cs index 4d12f34..42a1b2b 100644 --- a/IO/GraphFile.cs +++ b/IO/GraphFile.cs @@ -51,19 +51,16 @@ namespace Graph.IO graph.Vertices.ForEach(vertex => { // do nothing if it has no parent - if (vertex.Parent == null) + if (vertex.Parent == -1) return; - // needed due to making vertex.Parent nullable - int parent = vertex.Parent.GetValueOrDefault(); - // for vertex & parent, create string if not already lines[vertex.Id] ??= $"{vertex.Id}"; - lines[parent] ??= $"{parent}"; + lines[vertex.Parent] ??= $"{vertex.Parent}"; // add vertex + weight to parent's string & visa versa - lines[parent] += $" {vertex.Id} {vertex.Key.ToString("F1")}"; - lines[vertex.Id] += $" {parent} {vertex.Key.ToString("F1")}"; + lines[vertex.Parent] += $" {vertex.Id} {vertex.Key.ToString("F1")}"; + lines[vertex.Id] += $" {vertex.Parent} {vertex.Key.ToString("F1")}"; }); // write the array of strings to file writer.WriteAllLines(lines); @@ -10,7 +10,7 @@ namespace Graph public int Id { get; set; } public T Key { get; set; } - public int? Parent { get; set; } = null; + public int Parent { get; set; } = -1; public List<Edge<T>> Edges { get; set; } = new List<Edge<T>>(); // indexer for accessing edge with v of index |