-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',同時也反轉中間。有什麼問題? –
什麼是它;爲什麼你不明白'它'可以被扭轉? –