Last active
August 29, 2015 13:57
-
-
Save diegomichell/9567879 to your computer and use it in GitHub Desktop.
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
/* | |
* 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