/// <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(); }
/* * * 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(); }
/// <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(); }
static void Main(string[] args) { SortedList studentRecords = new SortedList(); studentRecords.Add("John"); studentRecords.Add("Peter"); studentRecords.Add("George"); studentRecords.Add("Paul"); studentRecords.Add("Martin"); studentRecords.SetSortingStrategy(new Quicksort()); studentRecords.Sort(); studentRecords.SetSortingStrategy(new MergeSort()); studentRecords.Sort(); Console.Read(); }
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 */ }
{ //encapsula um algoritimo dentro de uma classe static void Main(string[] args) { SortedList students = new SortedList(); students.Add("Aluno1"); students.Add("Aluno3"); students.Add("Aluno5"); students.Add("Aluno4"); students.Add("Aluno2"); students.setSortStrategy(new QuickSort()); students.Sort(); students.setSortStrategy(new ShellSort()); students.Sort(); students.setSortStrategy(new MergeSort()); students.Sort(); }
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(); }
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(); }
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(string[] args) { SortedList sortList = new SortedList(); sortList.Add("A"); sortList.Add("B"); sortList.Add("V"); sortList.Add("S"); sortList.SetStrategy(new ShellSort()); sortList.Sort(); sortList.Display(); Console.ReadKey(); }
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() { 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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
/// <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(); }
private static void Main() { // Two contexts following different strategies SortedList studentRecords = new SortedList(); studentRecords.Add("John"); studentRecords.Add("Peter"); studentRecords.Add("George"); studentRecords.Add("Paul"); studentRecords.Add("Martin"); studentRecords.SetSortingStrategy(new Quicksort()); studentRecords.Sort(); studentRecords.SetSortingStrategy(new Shellsort()); studentRecords.Sort(); studentRecords.SetSortingStrategy(new MergeSort()); studentRecords.Sort(); // Wait for user Console.Read(); }
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(); }
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(); }