Last active
June 21, 2024 00:38
-
-
Save hsynkrcf/72ae6d3670e05d3becbd6e54b7dbc96d to your computer and use it in GitHub Desktop.
Selection Sort Algorithm Performed On C#
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
public int[] SelectionSort(int[] arr) | |
{ | |
int n = arr.Length; | |
for (int i = 0; i < n - 1; i++) | |
{ | |
int minIdx = i; | |
for (int j = i + 1; j < n; j++) | |
{ | |
if (arr[j] < arr[minIdx]) | |
{ | |
minIdx = j; | |
} | |
} | |
int temp = arr[minIdx]; | |
arr[minIdx] = arr[i]; | |
arr[i] = temp; | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment