string rev(string& s)
{
string s1 = string(s.begin(), s.begin() + 1);//占用内存,递归深度过大的时候
string s2 = string(s.begin() + 1, s.end());
if (s2.size() == 1)
{
s = s2 + s1;
return s;
}
else
{
return s = rev(s2) + s1;
}
}
int main()
{
string s = "abcd";
cout << rev(s) << endl;
return 0;
}
{
string s1 = string(s.begin(), s.begin() + 1);//占用内存,递归深度过大的时候
string s2 = string(s.begin() + 1, s.end());
if (s2.size() == 1)
{
s = s2 + s1;
return s;
}
else
{
return s = rev(s2) + s1;
}
}
int main()
{
string s = "abcd";
cout << rev(s) << endl;
return 0;
}