-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Vertex.cs
58 lines (51 loc) · 1.87 KB
/
Vertex.cs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
namespace DataStructures.Graph;
/// <summary>
/// Implementation of graph vertex.
/// </summary>
/// <typeparam name="T">Generic Type.</typeparam>
public class Vertex<T>
{
/// <summary>
/// Gets vertex data.
/// </summary>
public T Data { get; }
/// <summary>
/// Gets an index of the vertex in graph adjacency matrix.
/// </summary>
public int Index { get; internal set; }
/// <summary>
/// Gets reference to the graph this vertex belongs to.
/// </summary>
public DirectedWeightedGraph<T>? Graph { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="Vertex{T}"/> class.
/// </summary>
/// <param name="data">Vertex data. Generic type.</param>
/// <param name="index">Index of the vertex in graph adjacency matrix.</param>
/// <param name="graph">Graph this vertex belongs to.</param>
public Vertex(T data, int index, DirectedWeightedGraph<T>? graph)
{
Data = data;
Index = index;
Graph = graph;
}
/// <summary>
/// Initializes a new instance of the <see cref="Vertex{T}"/> class.
/// </summary>
/// <param name="data">Vertex data. Generic type.</param>
/// <param name="index">Index of the vertex in graph adjacency matrix.</param>
public Vertex(T data, int index)
{
Data = data;
Index = index;
}
/// <summary>
/// Sets graph reference to the null. This method called when vertex removed from the graph.
/// </summary>
public void SetGraphNull() => Graph = null;
/// <summary>
/// Override of base ToString method. Prints vertex data and index in graph adjacency matrix.
/// </summary>
/// <returns>String which contains vertex data and index in graph adjacency matrix..</returns>
public override string ToString() => $"Vertex Data: {Data}, Index: {Index}";
}