Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. template <typename It, typename OutputIt>
  2. OutputIt sideways_merge(It first1, It last1, It first2, It last2, OutputIt out) {
  3.     --last2;
  4.     --first2;
  5.     while (first1 != last1 || last2 != first2) {
  6.         if (first1 == last1) {
  7.             *out++ = *last2--;
  8.         } else if (last2 == first2) {
  9.             *out++ = *first1++;
  10.         } else {
  11.             *out++ = (*first1 < *last2 ? *first1++ : *last2--);
  12.         }
  13.     }
  14.     return out;
  15.  
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement