Skip to content

Instantly share code, notes, and snippets.

@shoooe
Created February 25, 2014 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoooe/9202298 to your computer and use it in GitHub Desktop.
Save shoooe/9202298 to your computer and use it in GitHub Desktop.
Implementation of insertion sort as an exercise.
#pragma once
#include <algorithm>
template <typename IT>
void insertion_sort(IT begin, IT end) {
for (IT i = begin; i != end; ++i) {
for (IT j = i; j != begin; --j) {
if (*(j-1) > *j) std::iter_swap(j-1, j);
else break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment