Created
October 15, 2015 23:16
-
-
Save goldsborough/a974798b5568ebf35a43 to your computer and use it in GitHub Desktop.
Insert a sorted range into another sorted range, better solution.
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
template<typename Iterator1, typename Iterator2> | |
void sorted_insert(Iterator1 first_begin, | |
Iterator1 first_end, | |
Iterator2 second_begin, | |
Iterator2 second_end, | |
Iterator2 buffer_end) | |
{ | |
--first_begin; | |
--first_end; | |
--second_end; | |
--buffer_end; | |
for ( ; first_end != first_begin; --buffer_end) | |
{ | |
if (*first_end > *second_end) *buffer_end = *first_end--; | |
else *buffer_end = *second_end--; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment