示例#1
0
文件: Sorter.cs 项目: Azmalent/itmo4
        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;
        }
示例#2
0
文件: Sorter.cs 项目: Azmalent/itmo4
        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;
        }