blob: 614e22e93f9eceeece7cc5844462dffe15987db4 (
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using Interfaces;
namespace Graph
{
public class Vertex<T> : INode<T>, IComparable<INode<T>> where T : IComparable<T>
{
public int Id { get; set; }
public T Key { get; set; }
public int? Parent { get; set; } = null;
public List<Edge<T>> Edges { get; set; } = new List<Edge<T>>();
public Vertex(int id) =>
Id = id;
public Vertex(int id, List<Edge<T>> edges) : this(id) =>
Edges = edges;
public int CompareTo(INode<T> node) =>
Key.CompareTo(node.Key);
public override string ToString() => $"{Id} {String.Join(" ", Edges.Select(e => (e.V, e.Weight)))}";
}
}
|