forked from LucasCancio/design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26829ef
commit 69cb37c
Showing
8 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |