-5
从Pierre Fourgeaud(互联网)得到代码,但我不明白它是如何颠倒?该代码如何反转? (递归)
void reverse(string& word)
{
if (word.size() <= 1) return;
// Get the string without the first and the last char
string temp = word.substr(1, word.size() - 2);
// Reverse it
reverse(temp);
// Recompose the string
word = word.substr(word.size() - 1) + temp + word[0];
}
它计算'last + middle + first',同时也反转中间。有什么问题? –
什么是它;为什么你不明白'它'可以被扭转? –