Created
January 18, 2015 13:49
-
-
Save petomalina/0a1ddcfe7ffb095e45f6 to your computer and use it in GitHub Desktop.
Simple Selection sort
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
int *selectionSort(int *array, int count) { | |
// at is location of first unordered item, minimum is unordered list minimum | |
int at = 0, minimum = 0; | |
for(at = 0; at < count-1; at++) { | |
minimum = at; // set minimum to the current replacer | |
for(int i = at+1; i < count; i++) { // find minimum | |
if(array[i] < array[minimum]) { | |
minimum = i; | |
} | |
} | |
// swap | |
int temp = array[at]; | |
array[at] = array[minimum]; | |
array[minimum] = temp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment