diff options
Diffstat (limited to 'Graph.cs')
-rw-r--r-- | Graph.cs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Graph.cs b/Graph.cs new file mode 100644 index 0000000..59fa004 --- /dev/null +++ b/Graph.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; + +namespace Graph +{ + public class Graph<T> where T : IComparable<T> + { + public List<Vertex<T>> Vertices { get; set; } = new List<Vertex<T>>(); + + public void AddEdge(Edge<T> edge) + { + Vertex<T> vertex = Vertices.Find(u => u.Id == edge.U); + + if (vertex == null) + Vertices.Add(vertex = new Vertex<T>(edge.U)); + + vertex.Edges.Add(edge); + } + + public override string ToString() => $"{String.Join("\n", Vertices)}"; + } + +}
\ No newline at end of file |