Esempio n. 1
0
        public static void ShellSort(int[] input, ThreadRunner runner)
        {
            int iterationCount = 0;
            int n = input.Length;

            var m1 = new int[n];

            Array.Copy(input, m1, n);

            for (int gap = n / 100; gap > 0; gap /= 10)
            {
                for (int i = gap; i < n; i += 1)
                {
                    int temp = m1[i];

                    int j = i;
                    while (j >= gap && m1[j - gap] > temp)
                    {
                        m1[j] = m1[j - gap];
                        j    -= gap;
                    }

                    m1[j] = temp;

                    if (runner.MergeFinished)
                    {
                        return;
                    }
                    runner.UpdateArray(ref iterationCount, m1);
                }
            }

            runner.ShellFinished = true;
        }
Esempio n. 2
0
        public static void MergeSort(int[] input, ThreadRunner runner)
        {
            int iterationCount = 0;
            int n = input.Length;

            var m1 = new int[n];

            Array.Copy(input, m1, n);

            for (int i = 1; i < n; i *= 2)
            {
                for (int j = 0; j < n - i; j += 2 * i)
                {
                    int right = j + 2 * i;
                    if (n < right)
                    {
                        right = n;
                    }
                    Merge(m1, j, j + i, right);

                    if (runner.ShellFinished)
                    {
                        return;
                    }
                    runner.UpdateArray(ref iterationCount, m1);
                }
            }

            runner.MergeFinished = true;
        }
Esempio n. 3
0
        private static void DoneMessage(ThreadRunner runner)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nГотово.");
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine($"Первой завершилась сортировка {GetSortingMethod(runner)}.");

            Thread.Sleep(3000);
        }
Esempio n. 4
0
        private static string GetSortingMethod(ThreadRunner runner, bool titleCase = false)
        {
            string sort = runner.MergeFinished ? "слиянием" : "Шелла";

            if (titleCase)
            {
                return(char.ToUpper(sort[0]) + sort.Substring(1));
            }
            return(sort);
        }