Skip to content

Commit

Permalink
Strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCancio committed Jan 15, 2021
1 parent 26829ef commit 69cb37c
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 0 deletions.
6 changes: 6 additions & 0 deletions PatternsComportamentais/PatternsComportamentais.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Observer", "Observer\Observ
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "State", "State\State.csproj", "{D8399170-7DED-4CDC-8FB9-03F3C91CD142}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Strategy", "Strategy\Strategy.csproj", "{E577FEAF-A388-4BBB-B9D8-DF84075F08DC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -57,6 +59,10 @@ Global
{D8399170-7DED-4CDC-8FB9-03F3C91CD142}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8399170-7DED-4CDC-8FB9-03F3C91CD142}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8399170-7DED-4CDC-8FB9-03F3C91CD142}.Release|Any CPU.Build.0 = Release|Any CPU
{E577FEAF-A388-4BBB-B9D8-DF84075F08DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E577FEAF-A388-4BBB-B9D8-DF84075F08DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E577FEAF-A388-4BBB-B9D8-DF84075F08DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E577FEAF-A388-4BBB-B9D8-DF84075F08DC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
14 changes: 14 additions & 0 deletions PatternsComportamentais/Strategy/MergeSort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Strategy
{
public class MergeSort : SortStrategy
{
public override void Sort(List<string> list)
{
Console.WriteLine("Merge Sorted list");
}
}
}
26 changes: 26 additions & 0 deletions PatternsComportamentais/Strategy/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace Strategy
{
class Program
{
static void Main(string[] args)
{
SortedList studentRecords = new SortedList();
studentRecords.Add("Rodrigo");
studentRecords.Add("Maria");
studentRecords.Add("João");
studentRecords.Add("Carlos");
studentRecords.Add("Ana");

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

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

studentRecords.SetSortStategy(new MergeSort());
studentRecords.Sort();
}
}
}
15 changes: 15 additions & 0 deletions PatternsComportamentais/Strategy/QuickSort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Strategy
{
public class QuickSort : SortStrategy
{
public override void Sort(List<string> list)
{
list.Sort();
Console.WriteLine("Quick Sorted list");
}
}
}
14 changes: 14 additions & 0 deletions PatternsComportamentais/Strategy/ShellSort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Strategy
{
public class ShellSort : SortStrategy
{
public override void Sort(List<string> list)
{
Console.WriteLine("Shell Sorted list!");
}
}
}
11 changes: 11 additions & 0 deletions PatternsComportamentais/Strategy/SortStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Strategy
{
public abstract class SortStrategy
{
public abstract void Sort(List<string> list);
}
}
32 changes: 32 additions & 0 deletions PatternsComportamentais/Strategy/SortedList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Strategy
{
public class SortedList
{
private List<string> _list = new List<string>();
private SortStrategy _sortStrategy;

public void SetSortStategy(SortStrategy sortStrategy)
{
this._sortStrategy = sortStrategy;
}

public void Add(string name)
{
_list.Add(name);
}

public void Sort()
{
_sortStrategy.Sort(_list);

foreach (string name in _list)
{
Console.WriteLine($" {name}\n");
}
}
}
}
8 changes: 8 additions & 0 deletions PatternsComportamentais/Strategy/Strategy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>

0 comments on commit 69cb37c

Please sign in to comment.