Рекурсивная функция C++ для перемещения определенных символов в конец строки ⇐ C++
-
Anonymous
Рекурсивная функция C++ для перемещения определенных символов в конец строки
I am attempting to write a recursive function that, given a string, recursively computes a new string where all the lowercase 'x' chars have been moved to the end of the string.
For example,
moveXs("xxre") --> "rexx"
moveXs("xxhixx") --> "hixxxx"
moveXs("xhixhix") --> "hihixxx"
I am relatively new to C++ and especially to recursion (unfortunately the function must employ this method to solve the problem), so I am having trouble with this problem. Below is the code I have written thus far, but it seems to be returning only empty strings and I can't for the life of me figure out why.
string moveXs(const string& str) { string strCopy = str; if (strCopy.length()
Источник: https://stackoverflow.com/questions/264 ... -of-string
I am attempting to write a recursive function that, given a string, recursively computes a new string where all the lowercase 'x' chars have been moved to the end of the string.
For example,
moveXs("xxre") --> "rexx"
moveXs("xxhixx") --> "hixxxx"
moveXs("xhixhix") --> "hihixxx"
I am relatively new to C++ and especially to recursion (unfortunately the function must employ this method to solve the problem), so I am having trouble with this problem. Below is the code I have written thus far, but it seems to be returning only empty strings and I can't for the life of me figure out why.
string moveXs(const string& str) { string strCopy = str; if (strCopy.length()
Источник: https://stackoverflow.com/questions/264 ... -of-string
Мобильная версия