Skip to content

Instantly share code, notes, and snippets.

@diegomichell
Last active August 29, 2015 13:57
Show Gist options
  • Save diegomichell/9567879 to your computer and use it in GitHub Desktop.
Save diegomichell/9567879 to your computer and use it in GitHub Desktop.
/*
* Implementing Selection Sort.
*/
void sort(int values[], int n)
{
//while the list is out of order
for (int i = 0; i < n; i++)
{
int smallest = values[i];
int smallest_location = i;
//go through the entire list
for (int j = i + 1; j < n; j++)
{
//find the smallest number
if (smallest > values[j]){
smallest = values[j];
smallest_location = j;
}
}
//put the beginning of the list where the smallest number was
values[smallest_location] = values[i];
//place it on the beginning of the list
values[i] = smallest;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment