protected void MergeSort(int start, int middle, int end) { if (start >= end) { return; } MergeSort(start, (middle - start) / 2, middle); MergeSort(middle + 1, (end + middle + 1) / 2, end); int leftIndex = start; int rightIndex = middle + 1; int tmpIndex = 0; Kruskal_Edge <T>[] buffer = new Kruskal_Edge <T> [end - start + 1]; while (leftIndex <= middle && rightIndex <= end) { if (edges[leftIndex].Weight <= edges[rightIndex].Weight) { buffer[tmpIndex] = edges[leftIndex]; leftIndex++; } else { buffer[tmpIndex] = edges[rightIndex]; rightIndex++; } tmpIndex++; } while (leftIndex <= middle) { buffer[tmpIndex] = edges[leftIndex]; leftIndex++; tmpIndex++; } while (rightIndex <= end) { buffer[tmpIndex] = edges[rightIndex]; rightIndex++; tmpIndex++; } tmpIndex = 0; for (int i = start; i <= end; i++) { edges[i] = buffer[tmpIndex]; tmpIndex++; } }
public void AddEdge(Kruskal_Edge <T> edge) { AddVertice(edge.Source); AddVertice(edge.Destination); edges.Add(edge); }