writing a recursive return line function out of curiosity, but with few problems with XOR. The whole point of this function is not to use an iterator, so it is a recursive function. this is not homework, just curiosity.
private static char[] ReverseNL(char[] arr, int index) { var len = arr.Length; if (index > 0) arr[len - index] ^= arr[index - 1]; return index-- < 1 ? arr : ReverseNL(arr, index); }
Jamble seems to be the first part of my line
"Hey stop!" becomes "I ♫ → A ← E↨reht yeh"
it is always the first half of a phrase that is messed up ...
UPDATE ..
I believe that XOR is not needed here .. so the base job is used, also got rid of the return.
private static void ReverseNL(char[] arr, int index) { var len = arr.Length; if (index > 0 && index > len / 2) { var c = arr[len - index]; arr[len - index] = arr[index - 1]; arr[index - 1] = c; index--; ReverseNL(arr, index); } }
source share