summaryrefslogtreecommitdiffstats
path: root/Graph.cs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2021-03-28 01:53:40 +0000
committerToby Vincent <tobyv13@gmail.com>2021-03-28 01:53:40 +0000
commit1bab0bef287319c40b1451a12ae43686e39d5eba (patch)
tree88e06a905ed66580f43f44d981190e69cb4830aa /Graph.cs
parentbf4c7f3d9d7c69976aaa2f7c1b59d5e837d511c1 (diff)
added more documentation and cleaned up code
Diffstat (limited to 'Graph.cs')
-rw-r--r--Graph.cs8
1 files changed, 6 insertions, 2 deletions
diff --git a/Graph.cs b/Graph.cs
index 8521bd4..10381f1 100644
--- a/Graph.cs
+++ b/Graph.cs
@@ -14,19 +14,23 @@ namespace Graph
Vertices = vertices;
}
- // Indexer for accessing vertex with id of index
+ // indexer for accessing vertex with id of index
public Vertex<T> this[int index] { get => Vertices.Find(vertex => vertex.Id == index); }
+ // create virtex if needed, then add the edge to it's edges list
public void AddEdge(Edge<T> edge)
{
+ // look for existing vertex, and use it if found
Vertex<T> vertex = Vertices.Find(u => u.Id == edge.U);
if (vertex == null)
{
+ // if not found, create a new vertex
Vertices.Add(vertex = new Vertex<T>(edge.U));
vertex = Vertices[Vertices.Count - 1];
}
-
+
+ // add the edge to the new/found vertex
vertex.Edges.Add(edge);
}