I was trying to make different recursive functions for the same problem i.e. to reverse the letters of a word. While all my solutions with a void return type (where i just printed letters in reverse) worked, I've been trying to make one using the string return type but am running into a problem. When entered hello, the following code gives me l. And I can't seem to figure out why...
string reverse(string s)
{
int len = s.length();
if (len <= 1)
{
return s;
}
swap(s[0], s[len-1]);
return reverse(s.substr(1, len-2));
}