Skip to content

Instantly share code, notes, and snippets.

@ivankahl
Last active November 19, 2015 19:17
Show Gist options
  • Save ivankahl/99d426666fe1486f1859 to your computer and use it in GitHub Desktop.
Save ivankahl/99d426666fe1486f1859 to your computer and use it in GitHub Desktop.
Visual C#: Linear Sorting Algorithm
private static int[] SelectionSort(int[] items)
{
// Loop through each element
for (int i = 0; i < items.Length - 1; i++)
// Loop through each element afterwards
for (int j = i + 1; j < items.Length; j++)
// Check if the first item is bigger than the second item
if (items[i] > items[j])
{
// If it is, swap the two values
int tmp = items[i];
items[i] = items[j];
items[j] = tmp;
}
return items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment