Beispiel #1
0
        /// <resumen>

        /// Punto de entrada en la aplicación de consola.

        /// </resumen>

        static void Main(string[] args)
        {
            // Dos contextos siguiendo diferentes estrategias.

            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();

            /// Espera al usuario

            Console.ReadKey();
        }
Beispiel #2
0
        /*
         *
         * Define a family of algorithms, encapsulate each one, and make them interchangeable.
         */
        static void Main(string[] args)
        {
            SortedList sortedList = new SortedList();

            sortedList.Add(10);
            sortedList.Add(6);
            sortedList.Add(12);
            sortedList.Add(5);
            sortedList.Add(8);

            //SORT WITH QUICKSORT
            sortedList.SetSortStrategy(new QuickSort());
            sortedList.Sort();

            //sort with mergesort
            sortedList.SetSortStrategy(new MergeSort());
            sortedList.Sort();

            //sort with bubblesort
            sortedList.SetSortStrategy(new BubbleSort());
            sortedList.Sort();

            Console.WriteLine("Hello from stategy pattern");
            Console.ReadLine();
        }
Beispiel #3
0
        /// <summary>

        /// Entry point into console application.

        /// </summary>

        static void Main()
        {
            // 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)
        {
            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 MergeSort());
            studentRecords.Sort();
        }
        public static void Run()
        {
            Console.WriteLine("This real-world code demonstrates the Strategy pattern which encapsulates sorting algorithms in the form of sorting objects. This allows clients to dynamically change sorting strategies including Quicksort, Shellsort, and Mergesort.\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();

            /*
             * QuickSorted list
             * Anna
             * Jimmy
             * Samual
             * Sandra
             * Vivek
             *
             * ShellSorted list
             * Anna
             * Jimmy
             * Samual
             * Sandra
             * Vivek
             *
             * MergeSorted list
             * Anna
             * Jimmy
             * Samual
             * Sandra
             * Vivek
             */
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var studentRecords = new SortedList();

            studentRecords.Add("Rodrigo");
            studentRecords.Add("Maria");
            studentRecords.Add("João");
            studentRecords.Add("Carlos");
            studentRecords.Add("Ana");

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

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

            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();
        }
Beispiel #7
0
        public void Execute()
        {
            var 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.ReadKey();
        }
        static void Main(string[] args)
        {
            SortedList studants = new SortedList();

            studants.Add("geromel");
            studants.Add("kanneman");
            studants.Add("maicon");
            studants.Add("cavani");

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

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

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

            Console.ReadKey();
        }
        static void Main()
        {
            SortedList studentRecord = new SortedList();

            studentRecord.Add("Brian");
            studentRecord.Add("Jessica");
            studentRecord.Add("Bożydar");
            studentRecord.Add("ALfred");

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

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

            studentRecord.SetSortStrategy(new BubbleSort());
            studentRecord.Sort();

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

            studentRecords.Add("Rodrigo");
            studentRecords.Add("Maria");
            studentRecords.Add("João");
            studentRecords.Add("Carlos");
            studentRecords.Add("Pedro");

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

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

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

            Console.ReadKey();
        }
        static void Main()
        {
            SortedList studentRecord = new SortedList();

            studentRecord.Add("Ronny");
            studentRecord.Add("Bobby");
            studentRecord.Add("Kate");
            studentRecord.Add("Mike");
            studentRecord.Add("Ricky");

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

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

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

            Console.ReadKey();
        }
Beispiel #12
0
        public static void Main()
        {
            // Create list of students
            SortedList studentRecords = new SortedList();

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

            // Sort list using QuickSort strategy
            studentRecords.SetSortStrategy(new QuickSort());
            studentRecords.Sort();

            // Sort list using ShellSort strategy
            studentRecords.SetSortStrategy(new ShellSort());
            studentRecords.Sort();

            // Sort list using MergeSort strategy
            studentRecords.SetSortStrategy(new MergeSort());
            studentRecords.Sort();
        }
        static void Main(string[] args)
        {
            SortedList studentsRecords = new SortedList();

            studentsRecords.Add("Maria");
            studentsRecords.Add("João");
            studentsRecords.Add("Andrey");
            studentsRecords.Add("Marta");
            studentsRecords.Add("Lucas");
            studentsRecords.Add("Davi");

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

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

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

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

            sortedList.Add("Jessica");
            sortedList.Add("Julieta");
            sortedList.Add("Joao");
            sortedList.Add("Jose");
            sortedList.Add("Maria");
            sortedList.Add("Lucas");

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

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

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

            Console.Read();
        }
Beispiel #15
0
        static void Main()
        {
            SortedList students = new SortedList();

            students.Add("Janek");
            students.Add("Andzej");
            students.Add("Zygmunt");
            students.Add("Krzysiek");
            students.Add("Anna");

            students.SetSortStrategy(new QuickSort());
            students.Sort();
            students.Print();

            students.SetSortStrategy(new InsertionSort());
            students.Sort();

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

            Console.ReadKey();
        }
Beispiel #16
0
        public static void Main(string[] args)
        {
            var 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();
        }
Beispiel #17
0
        public static void Run()
        {
            SortedList records = new SortedList();

            records.Add("George");
            records.Add("John");
            records.Add("Allan");
            records.Add("Zoe");
            records.Add("Fred");
            records.Add("Thomas");

            records.SetSortStrategy(new AscendingSort());
            records.Sort();

            records.SetSortStrategy(new DescendingSort());
            records.Sort();

            records.SetSortStrategy(new FakeSort());
            records.Sort();

            Console.ReadKey();
        }
Beispiel #18
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // 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)
        {
            SortedList studentsRecords = new SortedList();

            studentsRecords.Add("Luiz Fernando");
            studentsRecords.Add("Lot");
            studentsRecords.Add("Gilmar");
            studentsRecords.Add("Fábio");
            studentsRecords.Add("Mateus");
            studentsRecords.Add("Gaspar");
            studentsRecords.Add("Leandro");
            studentsRecords.Add("Willian");

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

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

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

            Console.ReadKey();
        }
        private static void Main(string[] args)
        {
            // Two contexts following diffrent 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 ReverseSort());
            studentRecords.Sort();

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

            // Wait for user

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

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

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

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

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

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

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

            Console.ReadKey();
        }