Skip to content

Instantly share code, notes, and snippets.

@h0hmj
Created March 19, 2018 08:07
Show Gist options
  • Save h0hmj/edc9caa6310d80965b097b1c4cf58141 to your computer and use it in GitHub Desktop.
Save h0hmj/edc9caa6310d80965b097b1c4cf58141 to your computer and use it in GitHub Desktop.
selection sort
#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