public Graph(int verticesNum, int edgesNum) { Vertices = new GraphVertice[verticesNum]; for (int i = 0; i < verticesNum; ++i) { Vertices[i] = new GraphVertice(); } Edges = new GraphEdge[edgesNum]; }
static void AddVerticeToMST(GraphVertice vertice) { vertice.IsInMST = true; mstVertices.Add(vertice); mstValue += vertice.Weight; vertice.IsInMST = true; foreach (var edge in vertice.Edges) { var vert = Array.Find(edge.Vertices, v => !v.IsInMST); if (vert != null) { if (vert.Weight > edge.Value) { vert.Weight = edge.Value; } //TODO: need to optimise heap validation at this moment heap.Add(vert); } } }
static bool Compare(GraphVertice a, GraphVertice b) { return(a.Weight >= b.Weight); }
public GraphEdge(GraphVertice start, GraphVertice end, long value) { Vertices = new GraphVertice[] { start, end }; Value = value; }