Last active
March 5, 2016 22:30
-
-
Save ninjapanzer/5ea72adad3746ba6e97c to your computer and use it in GitHub Desktop.
Selection Sort
This file contains hidden or 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
| #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