Пример #1
0
        static void Main(string[] args)
        {
            var mergeSort = new MergeSort(GenerateArray(100000));

            mergeSort.Execute();

            var insertionSort = new InsertionSort(GenerateArray(100000));

            insertionSort.Execute();

            var selectionSort = new SelectionSort(GenerateArray(100000));

            selectionSort.Execute();

            var bubbleSort = new BubbleSort(GenerateArray(100000));

            bubbleSort.Execute();

            var quickSort = new QuickSort(GenerateArray(100000));

            quickSort.Execute();

            var dotnetSort = new DotnetLibrarySort(GenerateArray(100000));

            dotnetSort.Execute();

            var shellSort = new ShellSort(GenerateArray(100000));

            shellSort.Execute();
        }
Пример #2
0
        private static void TestShellSort()
        {
            var array = new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 };

            ShellSort.Sort(array);

            Console.WriteLine(string.Join(", ", array));
        }
Пример #3
0
        public void ShellSortSortsArray()
        {
            var testCollection = TestUtils.GetUnsortedCharArray();
            var algorithm      = new ShellSort();

            algorithm.Sort(testCollection);
            Assert.True(TestUtils.IsSorted(testCollection));
        }
Пример #4
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();
            //BubbleSort bubbleSort = new BubbleSort(50000);

            //for (int i = 0; i < 5; i++)
            //{
            //    bubbleSort.GenerateArray(ClassAlgorithms.SortType.reverseSorted);
            //    stopwatch.Start();
            //    bubbleSort.SortArray();
            //    stopwatch.Stop();
            //    Console.WriteLine(stopwatch.Elapsed);
            //    stopwatch.Reset();
            //}

            //InsertionSort insertionSort = new InsertionSort(50000);

            //for (int i = 0; i < 5; i++)
            //{
            //    insertionSort.GenerateArray(ClassAlgorithms.SortType.reverseSorted);
            //    stopwatch.Start();
            //    insertionSort.SortArray();
            //    stopwatch.Stop();
            //    Console.WriteLine(stopwatch.Elapsed);
            //    stopwatch.Reset();
            //}

            //SelectionSort selectionSort = new SelectionSort(50000);

            //for (int i = 0; i < 5; i++)
            //{
            //    selectionSort.GenerateArray(ClassAlgorithms.SortType.reverseSorted);
            //    stopwatch.Start();
            //    selectionSort.SortArray();
            //    stopwatch.Stop();
            //    Console.WriteLine(stopwatch.Elapsed);
            //    stopwatch.Reset();
            //}

            ShellSort shellSort = new ShellSort(50000);

            for (int i = 0; i < 5; i++)
            {
                shellSort.GenerateArray(ClassAlgorithms.SortType.sorted);
                stopwatch.Start();
                shellSort.SortArray();
                stopwatch.Stop();
                Console.WriteLine(stopwatch.Elapsed);
                stopwatch.Reset();
            }


            Console.ReadKey();
        }
Пример #5
0
        public void ShellSortTest()
        {
            // Arrange
            var arrayCount = 0;

            foreach (var sample in GenerateSampleArrays())
            {
                // Act
                ShellSort.Sort(sample);

                // Assert
                for (int i = 0; i < sample.Length - 1; i++)
                {
                    Assert.True(sample[i] <= sample[i + 1], $"Array #{arrayCount} was not sorted.");
                    arrayCount++;
                }
            }
        }