Advertisement
illfate

Untitled

Feb 26th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <algorithm>
  2. template< typename Iterator>
  3. void quick_sort(Iterator first, Iterator last) {
  4. if (first != last) {
  5. Iterator left = first;
  6. Iterator right = last;
  7. Iterator pivot = left++;
  8. while (left != right) {
  9. if (*left <= *pivot) {
  10. ++left;
  11. }
  12. else {
  13. while ((left != --right) && *pivot <= *right);
  14. std::iter_swap(left, right);
  15. }
  16. }
  17. --left;
  18. std::iter_swap(first, left);
  19. quick_sort(first, left);
  20. quick_sort(right, last);
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement