There is a constructed graph in which all vertices are given by instances of the Vertex class, and the faces are given by the Edge . Vertex have coordinates float x and float y , and Edge points Vertex a and Vertex b , the length double length . An attempt to write an algorithm for constructing a minimum spanning tree from the Delone graph using the Prima algorithm did not succeed. It turned out like this: 
Where the white edges are the edges of my "tree", and the gray ones in combination with the white ones are the original graph. Here is the code of my algorithm:
List<Vertex> tmpVertex = points; //вершины графа на входе List<Edge> tmpEdges = DelanayTree; //ребра графа входе List<Vertex> selectedVertex = new List<Vertex>(); //вершины, по которым "прошелся" алгоритм List<Edge> selectedEdges = new List<Edge>(); // окончательный граф (список ребер) selectedVertex.Add(tmpVertex[0]); ///подготовка (чтобы не вызвать исключение) tmpVertex.RemoveAt(0); foreach (Edge e in tmpEdges) //расчет длинны для каждого ребра { e.length = Math.Sqrt((Math.Abs(ebx - eax) * Math.Abs(ebx - eax)) + (Math.Abs(eby - eay) * Math.Abs(eby - eay))); } while (tmpVertex.Count > 0) //алгоритм будет работать пока есть над чем работать { List<Edge> conectedEdges = new List<Edge>(); foreach (Vertex v in selectedVertex) //получение ребер, связывающих выбранные точки { List<Edge> tmpConnEdges = v.getExtisEgdes(tmpEdges); foreach (Edge e in tmpConnEdges) conectedEdges.Add(e); } Edge minEdge = conectedEdges[0]; //чтобы не вызвать исключение foreach(Edge e in conectedEdges) //поиск ребра с меньшей длиной { if (e.length < minEdge.length) minEdge = e; } selectedEdges.Add(minEdge); //добавление его в финальный граф Vertex nonSelectedVertex; if (minEdge.a.vertexExtisInList(tmpVertex)) nonSelectedVertex = minEdge.a; //поиск второй (не выбранной) вершины этого ребра else nonSelectedVertex = minEdge.b; selectedVertex.Add(nonSelectedVertex); //добавление этой точки в финальный граф tmpEdges.Remove(minEdge); tmpVertex.Remove(nonSelectedVertex); } minimalTree = selectedEdges; What could be the error?
Math.Sqrt((Math.Abs(ebx - eax) * Math.Abs(ebx - eax)) + (Math.Abs(eby - eay) * Math.Abs(eby - eay)))? - hedgehogues