summaryrefslogtreecommitdiffstats
path: root/Graph.cs
diff options
context:
space:
mode:
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);
}