We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fa75dc1 commit f53fe3bCopy full SHA for f53fe3b
02_selection_sort/csharp/01_selection_sort/Program.cs
@@ -37,5 +37,24 @@ private static int FindSmallest(List<int> arr)
37
}
38
return smallestIndex;
39
40
+
41
+ public static int[] SelectionSort(int[] unorderedArray)
42
+ {
43
+ for (var i = 0; i < unorderedArray.Length; i++)
44
45
+ var smallestIndex = i;
46
47
+ for (var remainingIndex = i + 1; remainingIndex < unorderedArray.Length; remainingIndex++)
48
49
+ if (unorderedArray[remainingIndex] < unorderedArray[smallestIndex])
50
51
+ smallestIndex = remainingIndex;
52
+ }
53
54
+ (unorderedArray[i], unorderedArray[smallestIndex]) = (unorderedArray[smallestIndex], unorderedArray[i]);
55
56
57
+ return unorderedArray;
58
59
-}
60
+}
0 commit comments