Exemple #1
0
        static void Main(string[] args)
        {
            #region Comm Strategy
            CommunicateViaPhone communicateViaPhone = new CommunicateViaPhone();
            CommunicateViaEmail communicateViaEmail = new CommunicateViaEmail();
            CommunicateViaVideo communicateViaVideo = new CommunicateViaVideo();

            CommunicationService communicationService = new CommunicationService();
            // via phone
            communicationService.SetCommunicationMeans(communicateViaPhone);
            communicationService.Communicate("1234567");
            // via email
            communicationService.SetCommunicationMeans(communicateViaEmail);
            communicationService.Communicate("*****@*****.**");
            #endregion

            #region SortStrategy
            SortedList studentRecords = new SortedList();

            studentRecords.Add("Samual");
            studentRecords.Add("Jimmy");
            studentRecords.Add("Sandra");
            studentRecords.Add("Vivek");
            studentRecords.Add("Anna");

            studentRecords.SetSortStrategy(new QuickSort());
            studentRecords.Sort();
            studentRecords.SetSortStrategy(new ShellSort());
            studentRecords.Sort();
            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();
            #endregion

            Console.ReadKey();
        }
        public static void Main()
        {
            // Two contexts following different strategies
            // Но здесь, как мне кажется, плохой пример, потому что нет критериев выбора, сортировки просто
            // происходят процедурно, последовательно, и все на этом. Нужно условие, с помощью которого
            // будет ИМЕННО ПРОИСХОДИТЬ ВЫБОР ТОГО ИЛИ ИНОГО АЛГОРИТМА

            SortedList studentRecords = new SortedList();// создадим экземпляр класса SortedList

            //куда добавим следующий значения
            studentRecords.Add("Samual");
            studentRecords.Add("Jimmy");
            studentRecords.Add("Sandra");
            studentRecords.Add("Vivek");
            studentRecords.Add("Anna");

            studentRecords.SetSortStrategy(new QuickSort()); // и далее каждый раз один и тот же массив по разному отсортируем
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new ShellSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();

            // Wait for user

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            SortedList students = new SortedList();
            students.Add("Rose");
            students.Add("Lily");
            students.Add("sunflower");

            students.SelectSortingAlgo(new MergeSort());
            students.Sort();

            students.SelectSortingAlgo(new BubbleSort());
            students.Sort();
        }
        static void Main(string[] args)
        {
            SortedList students = new SortedList();

            students.Add("Rose");
            students.Add("Lily");
            students.Add("sunflower");

            students.SelectSortingAlgo(new MergeSort());
            students.Sort();

            students.SelectSortingAlgo(new BubbleSort());
            students.Sort();
        }
        static void Main(string[] args)
        {
            SortedList list = new SortedList();
            list.Add("Jack");
            list.Add("Marry");
            list.Add("Lucy");
            list.Add("Amber");

            list.SetSortStrategy(new QuickSort());
            list.Sort();
            list.ShowInfo();

            list.SetSortStrategy(new ShellSort());
            list.Sort();
            list.ShowInfo();
        }
        static void Main(string[] args)
        {
            SortedList list = new SortedList();

            list.Add("Jack");
            list.Add("Marry");
            list.Add("Lucy");
            list.Add("Amber");

            list.SetSortStrategy(new QuickSort());
            list.Sort();
            list.ShowInfo();

            list.SetSortStrategy(new ShellSort());
            list.Sort();
            list.ShowInfo();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            var context = new SortedList(new List<int> { 1, 4, 2, 6, 7, 3 }, new QuickSortStrategy());
            //var context = new SortedList(new List<int> { 1, 4, 2, 6, 7, 3 }, new MergeSortStrategy());
            //var context = new SortedList(new List<int> { 1, 4, 2, 6, 7, 3 }, new HeapSortStrategy());

            context.Sort();

            Console.ReadKey();
        }
Exemple #8
0
        static void Main(string[] args)
        {
            SortedList sortedList = new SortedList();

            sortedList.Add(5);
            sortedList.Add(11);
            sortedList.Add(25);
            sortedList.Add(7);
            sortedList.Add(8);

            sortedList.SetSortStrategy(new QuickSort());
            sortedList.Sort();

            sortedList.SetSortStrategy(new ShellSort());
            sortedList.Sort();

            sortedList.SetSortStrategy(new MergeSort());
            sortedList.Sort();

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            SortStrategy <int> quickSort = new QuickSort <int>();
            SortedList <int>   numbers   = new SortedList <int>();

            numbers.Sort(quickSort);

            SortStrategy <string> mergeSort = new MergeSort <string>();
            SortedList <string>   names     = new SortedList <string>();

            names.Sort(mergeSort);
        }
Exemple #10
0
        static void Main(string[] args)
        {
            var context = new SortedList(new List <int> {
                1, 4, 2, 6, 7, 3
            }, new QuickSortStrategy());

            //var context = new SortedList(new List<int> { 1, 4, 2, 6, 7, 3 }, new MergeSortStrategy());
            //var context = new SortedList(new List<int> { 1, 4, 2, 6, 7, 3 }, new HeapSortStrategy());

            context.Sort();

            Console.ReadKey();
        }
Exemple #11
0
        static void Main(string[] args)
        {
            SortedList studentRecords = new SortedList();

            studentRecords.Add("Samual");
            studentRecords.Add("Jimmy");
            studentRecords.Add("Sandra");
            studentRecords.Add("Vivek");
            studentRecords.Add("Anna");

            studentRecords.SetSortStrategy(new QuickSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new ShellSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();

            // Wait for user
            Console.ReadKey();
        }
Exemple #12
0
        public static void Main(string[] args)
        {
            // Two contexts following different strategies
            SortedList studentRecords = new SortedList();

            studentRecords.Add("Samual");
            studentRecords.Add("Jimmy");
            studentRecords.Add("Sandra");
            studentRecords.Add("Vivek");
            studentRecords.Add("Anna");

            studentRecords.SetSortStrategy(new QuickSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new ShellSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();

            // Wait for user
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("\n Vehiculo \n");

            Vehiculo v = new Vehiculo();

            v.ConduccionDeportiva();
            v.Acelerar(2.4f);

            Console.WriteLine("");

            v.ConduccionNormal();
            v.Acelerar(2.4f);



            Console.WriteLine("\n Ordenamiento \n");

            SortedList studentRecords = new SortedList();

            studentRecords.Add("Samual");
            studentRecords.Add("Jimmy");
            studentRecords.Add("Sandra");
            studentRecords.Add("Vivek");
            studentRecords.Add("Anna");

            studentRecords.SetSortStrategy(new QuickSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new ShellSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();

            Console.ReadLine();
        }
Exemple #14
0
        static void Main(string[] args)
        {
            SortedList list = new SortedList();

            list.Add("Martin");
            list.Add("Martin2");
            list.Add("Martin3");
            list.Add("Martin4");

            QuickSort sort = new QuickSort();
            list.SetSortStrategy(sort);

            list.Sort();

            Console.ReadKey();
        }
Exemple #15
0
        static void Main(string[] args)
        {
            SortedList studentRecords = new SortedList();

            studentRecords.Add("Samual");
            studentRecords.Add("Jimmy");
            studentRecords.Add("Sandra");
            studentRecords.Add("Vivek");
            studentRecords.Add("Anna");

            #region 可隨意替換

            studentRecords.SetSortStrategy(new QuickSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new ShellSort());
            studentRecords.Sort();

            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();

            #endregion

            // Wait for user
            Console.ReadKey();
        }
Exemple #16
0
        static void Main(string[] args)
        {
            #region MyRegion
            // Three contexts following different strategies
            Context c = new Context(new ConcreteStrategyA());
            c.ContextInterface();

            Context d = new Context(new ConcreteStrategyB());
            d.ContextInterface();

            Context e = new Context(new ConcreteStrategyC());
            e.ContextInterface();
            #endregion

            #region MyRegion
            SortedList studentRecords = new SortedList();
            studentRecords.Add("Samual");
            studentRecords.Add("Jimmy");
            studentRecords.Add("Sandra");
            studentRecords.Add("Anna");
            studentRecords.Add("Vivek");

            studentRecords.SetSortStrategy(new QuickSort());
            studentRecords.Sort();
            studentRecords.Display();
            #endregion

            Console.ReadLine();
        }