#include <iostream>
#include <vector>
using namespace std;
template <class Container>
void insert_sorted(Container& where, Container& what)
{
typename Container::iterator src = what.begin();
typename Container::iterator src_end = what.end();
size_t index = 0;
while(src != src_end)
{
if(*src < where[index])
{
where.insert(where.begin() + index, *src);
++src;
}
++index;
}
}
int main()
{
vector<int> foo{ 0, 5, 7, 9, 11, 14 };
vector<int> bar{ 1, 2, 4, 8, 10, 12 };
insert_sorted(foo, bar);
for(vector<int>::iterator i = foo.begin(); i != foo.end(); ++i)
{
cout << *i << " ";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlIDxjbGFzcyBDb250YWluZXI+CnZvaWQgaW5zZXJ0X3NvcnRlZChDb250YWluZXImIHdoZXJlLCBDb250YWluZXImIHdoYXQpCnsKCXR5cGVuYW1lIENvbnRhaW5lcjo6aXRlcmF0b3Igc3JjID0gd2hhdC5iZWdpbigpOwoJdHlwZW5hbWUgQ29udGFpbmVyOjppdGVyYXRvciBzcmNfZW5kID0gd2hhdC5lbmQoKTsKCQoJc2l6ZV90IGluZGV4ID0gMDsKCQoJd2hpbGUoc3JjICE9IHNyY19lbmQpCgl7CgkJaWYoKnNyYyA8IHdoZXJlW2luZGV4XSkKCQl7CgkJCXdoZXJlLmluc2VydCh3aGVyZS5iZWdpbigpICsgaW5kZXgsICpzcmMpOwoJCQkrK3NyYzsKCQl9CgkJCSsraW5kZXg7Cgl9Cn0KCmludCBtYWluKCkKewoJdmVjdG9yPGludD4gZm9veyAwLCA1LCA3LCA5LCAxMSwgMTQgfTsKCXZlY3RvcjxpbnQ+IGJhcnsgMSwgMiwgNCwgOCwgMTAsIDEyIH07CgkKCWluc2VydF9zb3J0ZWQoZm9vLCBiYXIpOwoJCglmb3IodmVjdG9yPGludD46Oml0ZXJhdG9yIGkgPSBmb28uYmVnaW4oKTsgaSAhPSBmb28uZW5kKCk7ICsraSkKCXsKCQljb3V0IDw8ICppIDw8ICIgIjsKCX0KCQoJcmV0dXJuIDA7Cn0=