Skip to content

Instantly share code, notes, and snippets.

@hsynkrcf
Last active June 21, 2024 00:38
Show Gist options
  • Save hsynkrcf/72ae6d3670e05d3becbd6e54b7dbc96d to your computer and use it in GitHub Desktop.
Save hsynkrcf/72ae6d3670e05d3becbd6e54b7dbc96d to your computer and use it in GitHub Desktop.
Selection Sort Algorithm Performed On C#
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