To start with, let's take a look at the code of the generic class representing a single node in a graph. Such a class is named Node and its code is shown as follows:
public class Node<T> { public int Index { get; set; } public T Data { get; set; } public List<Node<T>> Neighbors { get; set; } = new List<Node<T>>(); public List<int> Weights { get; set; } = new List<int>(); public override string ToString() { return $"Node with index {Index}: {Data}, neighbors: {Neighbors.Count}"; } }
The class contains four properties. As all of these elements perform important roles in the code snippets shown in this chapter, let's analyze them in detail:
- The first property (Index) stores an index of a particular node in a collection of nodes in a graph ...