Skip to content

Instantly share code, notes, and snippets.

@ninjapanzer
Last active March 5, 2016 22:30
Show Gist options
  • Select an option

  • Save ninjapanzer/5ea72adad3746ba6e97c to your computer and use it in GitHub Desktop.

Select an option

Save ninjapanzer/5ea72adad3746ba6e97c to your computer and use it in GitHub Desktop.
Selection Sort
#include <iostream>
int main() {
const int SIZE = 10;
int unsorted[SIZE] = {5,3,1,6,8,2,9,0,4,7};
for(int i = 0; i < SIZE - 1; i++){
int current_pos = i;
for(int j = i + 1; j < SIZE; j++){
if(unsorted[j] < unsorted[current_pos]){
current_pos = j;
}
}
int temp = unsorted[i];
unsorted[i] = unsorted[current_pos];
unsorted[current_pos] = temp;
//std::cout << unsorted[i] << " " << unsorted[j] << std::endl;
}
for(int i = 0; i < SIZE; i++){
std::cout << unsorted[i] << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment