Given we can do a left-rotate (and subsequently a right-rotate) of an array only in terms of calls to reverse, like so:
void rotl(std::string &s, const int d)
{
std::reverse(s.begin() , s.begin() + d);
std::reverse(s.begin() + d, s.end() );
std::reverse(s.begin() , s.end() );
}
What would the algorithm be to reverse an array/string in terms of only rotating operations?
There's a loop-wise process which rotates the array of lengths N, n-times, but I was wondering if there's a simple approach similar to the above using reverse but only using rotate calls.
rotl
on a subarray (where.end()
would indicate the end of that subarray)? Can you share the "loop-wise process" you mentioned? – Leisrotl
can be called on subarrays? Or else tag your question withc++
? – Leisrotl
calls on subarrays, then yes, it is possible, but this seems something you already mention in your post as a possibility (loop-wise). Is it maybe that you are looking for a way to do it with a fixed number ofrotl
calls, no matter how large the size of the original array is? I'm just trying to understand what you are asking here. Because the last paragraph of your post seems to answer the question in the title of your post. What exactly makes that approach not "simple" enough? – Leis