diff options
author | Toby Vincent <tobyv13@gmail.com> | 2021-03-28 01:53:40 +0000 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2021-03-28 01:53:40 +0000 |
commit | 1bab0bef287319c40b1451a12ae43686e39d5eba (patch) | |
tree | 88e06a905ed66580f43f44d981190e69cb4830aa /Graph.cs | |
parent | bf4c7f3d9d7c69976aaa2f7c1b59d5e837d511c1 (diff) |
added more documentation and cleaned up code
Diffstat (limited to 'Graph.cs')
-rw-r--r-- | Graph.cs | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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); } |