using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Advanced.Algorithms.DataStructures.Graph
{
///
/// UnDirected graph. (When implemented on a directed graphs only outgoing edges are considered as Edges).
///
///
public interface IGraph
{
bool IsWeightedGraph { get; }
int VerticesCount { get; }
IGraphVertex ReferenceVertex { get; }
bool ContainsVertex(T key);
IGraphVertex GetVertex(T key);
IEnumerable> VerticesAsEnumberable { get; }
bool HasEdge(T source, T destination);
IGraph Clone();
}
public interface IGraphVertex
{
T Key { get; }
IEnumerable> Edges { get; }
IEdge GetEdge(IGraphVertex targetVertex);
}
public interface IEdge
{
W Weight() where W : IComparable;
T TargetVertexKey { get; }
IGraphVertex TargetVertex { get; }
}
internal class Edge : IEdge where C : IComparable
{
private object weight;
internal Edge(IGraphVertex target, C weight)
{
this.TargetVertex = target;
this.weight = weight;
}
public T TargetVertexKey => TargetVertex.Key;
public IGraphVertex TargetVertex { get; private set; }
public W Weight() where W : IComparable
{
return (W)weight;
}
}
}