Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var   result = PrintMenu();
            ITask task;

            switch (result)
            {
            case 1:
                task = new BubbleSortTask();
                break;

            case 2:
                task = new SelectionSortTask();
                break;

            case 3:
                task = new InsertionSortTask();
                break;

            case 4:
                task = new ShellSortTask();
                break;

            case 5:
                task = new HeapSortTask();
                break;

            default:
                return;
            }

            Console.WriteLine("Random Array.");
            var t = new TestRunner(task, $"data/0.random/");

            t.Run();

            Console.WriteLine("Digits Array.");
            t = new TestRunner(task, $"data/1.digits/");
            t.Run();

            Console.WriteLine("Sorted Array.");
            t = new TestRunner(task, $"data/2.sorted/");
            t.Run();

            Console.WriteLine("Reverse Array.");
            t = new TestRunner(task, $"data/3.revers/");
            t.Run();

            Console.WriteLine("Completed. Press ENTER to exit.");
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //1
            double eps    = 0;
            double dx     = 9;
            int    x0     = 2;
            Newton newton = new Newton(eps);

            Console.WriteLine("Результат: " + newton.Exec(x0, dx));

            //Task2
            int[,] array = { { 26, 22, 14 }, { 23, 5, 13 }, { 44, 8, 11 } };
            Console.WriteLine("Input array");
            BubbleSortTask.Display(array);

            SumSort ss     = new SumSort(true);
            Sorter  sorter = new Sorter(ss);

            Console.WriteLine("\r\nIn order of decreasing sums of elements of rows of the matrix");
            sorter.ChangeSortType(new SumSort(false));
            array = sorter.Sort(array);
            BubbleSortTask.Display(array);

            Console.WriteLine("\r\nIn order of increasing sums of elements of rows of the matrix");
            sorter.ChangeSortType(new SumSort(true));
            array = sorter.Sort(array);
            BubbleSortTask.Display(array);

            Console.WriteLine("\r\nIn order of decreasing max element of rows of the matrix");
            sorter.ChangeSortType(new MaxSort(false));
            array = sorter.Sort(array);
            BubbleSortTask.Display(array);

            Console.WriteLine("\r\nIn order of increasing max element of rows of the matrix");
            sorter.ChangeSortType(new MaxSort(true));
            array = sorter.Sort(array);
            BubbleSortTask.Display(array);

            Console.WriteLine("\r\nIn order of decreasing min element of rows of the matrix");
            sorter.ChangeSortType(new MinSort(false));
            array = sorter.Sort(array);
            BubbleSortTask.Display(array);

            Console.WriteLine("\r\nIn order of increasing min element of rows of the matrix");
            sorter.ChangeSortType(new MinSort(true));
            array = sorter.Sort(array);
            BubbleSortTask.Display(array);
            Console.ReadKey();
        }