public void FindMinimumSpanningTree() { QData[] data = new QData[graph.QData.Length]; graph.QData.CopyTo(data, 0); while (VertexQueue.Count != 0) { VertexQueue.Dequeue(); QData curdata = data.Where(c => c != null).OrderBy(c => c.KeyValue).FirstOrDefault(); int u = curdata.Vertex; data.SetValue(null, u - 1); Node node = graph.Nodes.FirstOrDefault(c => c != null && c.Vertex == u); int j = 0; if (node == null) { continue; } while (node.Neighbours[j] != null) { if (data.FirstOrDefault(c => c != null && c.Vertex == node.Neighbours[j].Vertex) != null) { int v = node.Neighbours[j].Vertex - 1; if (node.Neighbours[j].Distance < graph.QData[v].KeyValue) { graph.QData[v].KeyValue = node.Neighbours[j].Distance; graph.QData[v].ParentValue = u; } } j++; } } }
private void InitializeMinSpanTreeNodes() { for (int i = 0; i < graph.QData.Length; i++) { graph.QData[i] = new QData(); graph.QData[i].Vertex = (i + 1); graph.QData[i].KeyValue = INF; graph.QData[i].ParentValue = -1; VertexQueue.Enqueue(i); } graph.QData[0].KeyValue = 0; RootNode = graph.QData[0]; }