Created
May 25, 2015 16:31
-
-
Save shoooe/ae15abf0e38ae1b281a0 to your computer and use it in GitHub Desktop.
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
namespace detail { | |
template<typename It> | |
It partition(It begin, It end) { | |
if (begin == end) return end; | |
auto pivot = *(end - 1); | |
auto left = begin; // left partion past the end | |
for (auto right = begin; right != end; ++right) { | |
if (*right <= pivot) { | |
std::iter_swap(left, right); | |
++left; | |
} | |
} | |
return left; | |
} | |
} | |
template<typename It> | |
void quick_sort(It begin, It end) { | |
if (begin == end) return; | |
auto pivot = detail::partition(begin, end); | |
quick_sort(begin, pivot - 1); | |
quick_sort(pivot, end); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment