Skip to content

Instantly share code, notes, and snippets.

@h0hmj
Created March 19, 2018 08:16
Show Gist options
  • Save h0hmj/caf2968b94d7210c6fe5c2492c33171c to your computer and use it in GitHub Desktop.
Save h0hmj/caf2968b94d7210c6fe5c2492c33171c to your computer and use it in GitHub Desktop.
insertion sort
#include <utility>
#include <vector>
void insertion_sort(std::vector<int>& nums) {
for (int i = 0; i < nums.size(); i++) {
int j = i;
while (j > 0 && nums[j] < nums[j - 1]) {
std::swap(nums[j], nums[j - 1]);
j--;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment