Example #1
0
        static void Main(string[] args)
        {
            ShowInfo();
            MyStruct[] arr = new[]
            {
                new MyStruct(4), new MyStruct(40), new MyStruct(87), new MyStruct(8), new MyStruct(4), new MyStruct(2),
                new MyStruct(78), new MyStruct(18), new MyStruct(5), new MyStruct(13), new MyStruct(6), new MyStruct(1)
            };
            List <MyStruct>   mas = new List <MyStruct>(arr);
            MyMass <MyStruct> m   = new MyMass <MyStruct>(mas);



            var mc = m.Clone();

            //var strat = new Context();


            Console.WriteLine("Не отсортированный массив " + m.ToString());

            //strat.SetStrategy(new BubleSort());
            //strat.DoSomeLogic(m, new IntComparep());
            var strat = new BubleSort <MyStruct>(new IntComparep(), GetInt);

            strat.DoAlgorithm(m, true);

            Console.WriteLine("Buble sort " + m.ToString());

            strat.DoAlgorithm(m, false);
            Console.WriteLine("Reverse buble sort " + m.ToString());


            var strat1 = new MergeSort <MyStruct>(new IntComparep(), GetInt);

            strat1.DoAlgorithm(m, true);

            Console.WriteLine("Merge sort " + m.ToString());

            strat1.DoAlgorithm(m, false);
            Console.WriteLine("Reverse merge sort " + m.ToString());


            var strat2 = new QuickSort <MyStruct>(new IntComparep(), GetInt);

            strat2.DoAlgorithm(m, true);

            Console.WriteLine("Quick sort " + m.ToString());

            strat2.DoAlgorithm(m, false);
            Console.WriteLine("Quick buble sort " + m.ToString());


            var strat3 = new HeapSort <MyStruct>(new IntComparep(), GetInt);

            strat3.DoAlgorithm(m, true);

            Console.WriteLine("heap sort " + m.ToString());

            strat3.DoAlgorithm(m, false);
            Console.WriteLine("Reverse heap sort " + m.ToString());



            var strat5 = new SelectionSort <MyStruct>(new IntComparep(), GetInt);

            strat5.DoAlgorithm(m, true);

            Console.WriteLine("Selection sort " + m.ToString());

            strat5.DoAlgorithm(m, false);
            Console.WriteLine("Reverse selection sort " + m.ToString());
            var strat4 = new IsertionSort <MyStruct>(new IntComparep(), GetInt);

            strat4.DoAlgorithm(m, true);

            Console.WriteLine("Insertion sort " + m.ToString());

            strat4.DoAlgorithm(m, false);
            Console.WriteLine("Reverse insertion sort " + m.ToString());



            //strat.SetStrategy(new SelectionSort());
            //strat.DoSomeLogic(m, new IntComparep());
            //Console.WriteLine("Selection sort " + m.ToString());
            //strat.DoSomeLogic(m, new IntComparep(), false);
            //Console.WriteLine("Reverse Selection sort " + m.ToString());

            //strat.SetStrategy(new IsertionSort());
            //strat.DoSomeLogic(m, new IntComparep());
            //Console.WriteLine("Insertion sort " + m.ToString());
            //strat.DoSomeLogic(m, new IntComparep(), false);
            //Console.WriteLine("Reverse insertion sort " + m.ToString());

            //strat.SetStrategy(new QuickSort());
            //strat.DoSomeLogic(m, new IntComparep());
            //Console.WriteLine("Quick sort " + m.ToString());
            //strat.DoSomeLogic(m, new IntComparep(), false);
            //Console.WriteLine("Reverse quick sort " + m.ToString());

            //strat.SetStrategy(new MergeSort());
            //strat.DoSomeLogic(m, new IntComparep());
            //Console.WriteLine("Merge sort " + m.ToString());
            //strat.DoSomeLogic(m, new IntComparep(), false);
            //Console.WriteLine("Reverse merge sort " + m.ToString());

            //strat.SetStrategy(new HeapSort());
            //strat.DoSomeLogic(m, new IntComparep());
            //Console.WriteLine("Heap sort " + m.ToString());
            //strat.DoSomeLogic(m, new IntComparep(), false);
            //Console.WriteLine("Reverse heap sort " + m.ToString());
        }