Created
March 19, 2018 08:07
-
-
Save h0hmj/edc9caa6310d80965b097b1c4cf58141 to your computer and use it in GitHub Desktop.
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
#include <utility> | |
#include <vector> | |
void selection_sort(std::vector<int>& nums) { | |
for (int i = 0; i < nums.size(); i++) { | |
int min = i; | |
for (int j = i + 1; j < nums.size(); j++) { | |
if (nums[j] < nums[min]) { | |
min = j; | |
} | |
} | |
std::swap(nums[i], nums[min]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment