c sharp create adjacency matrix code example
Example 1: creating weighted graph in c#
public class Arc
{
public int Weigth;
public Node Parent;
public Node Child;
}
Example 2: creating weighted graph in c#
public class Node
{
public string Name;
public List<Arc> Arcs = new List<Arc>();
public Node(string name)
{
Name = name;
}
public Node AddArc(Node child, int w)
{
Arcs.Add(new Arc
{
Parent = this,
Child = child,
Weigth = w
});
if (!child.Arcs.Exists(a => a.Parent == child && a.Child == this))
{
child.AddArc(this, w);
}
return this;
}
}