Created
February 25, 2014 03:46
-
-
Save shoooe/9202298 to your computer and use it in GitHub Desktop.
Implementation of insertion sort as an exercise.
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
#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