I\'m looking for a way to rotate a string in c++. I spend all of my time in python, so my c++ is very rusty.
Here is what I want it to do: if I have a strin
At some point i was obsessed with divide and conquer, and used the following
since it 'Divides' the problem to smaller problems my guess is that this performs better. Expert comments on complexity and memory access behavior are welcome :).
Initial Call:
rotate_about(rots_g, 0, i, j - 2);
void rotate_about(char *str, int start, int pivot, int end)
{
if(pivot == start)
{
return ;
}
else if((pivot - start) <= (end - pivot))
{
int move_bytes = pivot-start;
swap_bytes(&str[start], &str[pivot],move_bytes);
rotate_about(str,pivot,pivot+move_bytes,end);
}
else
{
int move_bytes = end - pivot + 1;
swap_bytes(&str[start], &str[pivot],move_bytes);
rotate_about(str, start+move_bytes ,pivot,end);
}
}