Esempio n. 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 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();
        }
Esempio n. 5
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();
        }
Esempio n. 6
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();
        }
Esempio n. 7
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();
        }
Esempio n. 8
0
        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();
        }
Esempio n. 9
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();
        }
Esempio n. 10
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();
        }
Esempio n. 11
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();
        }