Skip to content

Instantly share code, notes, and snippets.

@shoooe
Created May 25, 2015 16:31
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/ae15abf0e38ae1b281a0 to your computer and use it in GitHub Desktop.
Save shoooe/ae15abf0e38ae1b281a0 to your computer and use it in GitHub Desktop.
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