Advertisement
Radfler

::bubble_sort

Sep 17th, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <algorithm>
  2. #include <functional>
  3.  
  4. template<typename ForwardIt, typename Compare>
  5. void bubble_sort(ForwardIt first, ForwardIt last, Compare comp) {
  6.     for(ForwardIt x = first; x != last; ++x) {
  7.         for(ForwardIt y = first; y != last; ++y) {
  8.             if(comp(*x, *y)) {
  9.                 std::iter_swap(x, y);
  10.             }
  11.         }
  12.     }
  13. }
  14.  
  15. template<typename ForwardIt>
  16. void bubble_sort(ForwardIt first, ForwardIt last) {
  17.     bubble_sort(first, last, std::less<>());
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement