Trying to implement an algorithm with Java where the method will take an input array, starting index and ending index, and will recursively reverse the array with a swap function. The method will properly swap the base case, but it will return that state as the answer.
public static char[] stringRecursion(char[] a, int p, int q) {
if (q < p) {
return swap(a, p, q);
}
return stringRecursion(a, p+1, q-1);
}
public static char[] swap(char[] a, int p, int q) {
char temp = a[p];
a[p] = a[q];
a[q] = temp;
return a;
}