How about this:
std::string merge(std::string a, std::string b) {
if (a.size() == 0) return b;
if (b.size() == 0) return a;
if (a.back() < b.back()) {
std::string m = merge(a, b.substr(0, b.size()-1));
return m + b.back();
}
else {
std::string m = merge(a.substr(0, a.size()-1), b);
return m + a.back();
}
}
Correctness and termination should be obvious, and I think it should fit the constraints you are given. But I wonder what teacher would pose such a task in C++, for the above code is about as inefficient as it possibly can be.