blob: 5841035232c84a96b4d09d973d89a27985e6207e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
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 Graph() { }
public Graph(List<Vertex<T>> vertices)
{
Vertices = vertices;
}
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)}";
}
}
|