Пример #1
0
        public void TestCaseAscending()
        {
            SampleArray <int> .Get(out int[] arr, out int[] arrCopy, () => _random.Next(0, 100));

            Array.Sort(arrCopy);
            var sort   = new MergeSort <int>();
            var actual = sort.MSort(arr);

            Assert.Equal(arrCopy, actual);
        }
Пример #2
0
        public void TestCaseDescending()
        {
            SampleArray <int> .Get(out int[] arr, out int[] arrCopy, () => _random.Next(0, 100));

            Array.Sort(arrCopy, new Comparison <int>((x, y) => y.CompareTo(x)));
            var sort   = new MergeSort <int>(Comparer <int> .Create(new Comparison <int>((x, y) => y.CompareTo(x))));
            var actual = sort.MSort(arr);

            Assert.Equal(arrCopy, actual);
        }
Пример #3
0
        static void Main(string[] args)
        {
            // First task.

            var builder = new CollectionBuilder();

            var firstStack  = builder.GenerateStack(new Random().Next(8, 13), 9);
            var secondStack = builder.GenerateStack(new Random().Next(8, 13), 9);
            var resultStack = StackComparison.CompareStacks(firstStack, secondStack);

            CollectionDisplay.Display("First stack", firstStack);
            CollectionDisplay.Display("Second stack", secondStack);
            CollectionDisplay.Display("Result stack", resultStack);
            Console.WriteLine();

            // Second task.

            var queue = new Queue <int>(builder
                                        .GenerateArrayWithDifferentNumbers(new Random().Next(10, 20), 100));

            CollectionDisplay.Display("Queue", queue);
            var sum = SumOfQueueMembers.FindSum(queue);

            Console.WriteLine($"Sum: {sum}");

            // Third task.

            var queue1 = new Queue <int>(builder.GenerateArray(new Random().Next(10, 15)));

            ThirdTask.ThirdTask.CountInCircle(queue1);
            Console.WriteLine("\n");

            // Sorting.

            Console.WriteLine("Quick sort");
            var array = builder.GenerateArray(new Random().Next(15, 20), 33);

            CollectionDisplay.Display("Array", array);
            QuickSort.QSort(array, 0, array.Length - 1);
            CollectionDisplay.Display("Result array", array);

            Console.WriteLine("Merge Sort");
            array = builder.GenerateArray(new Random().Next(15, 20), 33);
            CollectionDisplay.Display("Array", array);
            var resultArray = MergeSort.MSort(array);

            CollectionDisplay.Display("Result array", resultArray);
        }