From 751cc47da0d893ea0d644b866f0dbee804bcbe8f Mon Sep 17 00:00:00 2001 From: Kuzivanov Sergey <43182277+SergeyKuz1001@users.noreply.github.com> Date: Sun, 8 Dec 2019 12:55:25 +0300 Subject: [PATCH] Update ParallelAlgoKruskal.cs --- Task02/ParallelAlgoKruskal.cs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Task02/ParallelAlgoKruskal.cs b/Task02/ParallelAlgoKruskal.cs index 998ff74..4feee45 100644 --- a/Task02/ParallelAlgoKruskal.cs +++ b/Task02/ParallelAlgoKruskal.cs @@ -5,6 +5,7 @@ namespace Task02 { public class ParallelAlgoKruskal { + static Random rand = new Random(); static int[] dsu; static int parallelDepth = 3; // глубина рекурсии, до которой происходит распараллеливание сортировки рёбер @@ -19,7 +20,7 @@ static bool unionDsu(int x, int y) y = getDsu(y); if (x == y) return false; - if ((x + 2 * y) % 4 * 2 % 6 != 0) // псевдорандом + if (rand.Next(0, 1) == 1) // псевдорандом dsu[y] = x; else dsu[x] = y; @@ -48,26 +49,16 @@ static void parallelSort(T[] edges, T[] buffer, int LIndex, int RIndex, int p int i = LIndex, j = MIndex; for (int k = LIndex; k < RIndex; k++) { - if (i == MIndex) + if (i == MIndex || (j != RIndex && edges[i].CompareTo(edges[j]) >= 0)) { buffer[k] = edges[j]; j++; } - else if (j == RIndex) - { - buffer[k] = edges[i]; - i++; - } - else if (edges[i].CompareTo(edges[j]) < 0) + else { buffer[k] = edges[i]; i++; } - else - { - buffer[k] = edges[j]; - j++; - } } for (int k = LIndex; k < RIndex; k++) edges[k] = buffer[k];