diff --git a/02_selection_sort/csharp/01_selection_sort/Program.cs b/02_selection_sort/csharp/01_selection_sort/Program.cs index 4b5a1bd..77d0a09 100644 --- a/02_selection_sort/csharp/01_selection_sort/Program.cs +++ b/02_selection_sort/csharp/01_selection_sort/Program.cs @@ -37,5 +37,24 @@ namespace ConsoleApplication } return smallestIndex; } + + public static int[] SelectionSort(int[] unorderedArray) + { + for (var i = 0; i < unorderedArray.Length; i++) + { + var smallestIndex = i; + + for (var remainingIndex = i + 1; remainingIndex < unorderedArray.Length; remainingIndex++) + { + if (unorderedArray[remainingIndex] < unorderedArray[smallestIndex]) + { + smallestIndex = remainingIndex; + } + } + (unorderedArray[i], unorderedArray[smallestIndex]) = (unorderedArray[smallestIndex], unorderedArray[i]); + } + + return unorderedArray; + } } -} +} \ No newline at end of file