Skip to content

Instantly share code, notes, and snippets.

@petomalina
Created January 18, 2015 13:49
Show Gist options
  • Save petomalina/0a1ddcfe7ffb095e45f6 to your computer and use it in GitHub Desktop.
Save petomalina/0a1ddcfe7ffb095e45f6 to your computer and use it in GitHub Desktop.
Simple Selection sort
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