Question: The following recursive function reverse takes as parameters as integer array A and two other integers leftindex and rightindex which are indices of A.
The following recursive function reverse takes as parameters as integer array A and two other integers leftindex and rightindex which are indices of A. After the function returns, only the part of the array from leftindex to rightIndex (including both) should be reversed if leftindex < rightIndex. For example, if the elements of the array A are 1, 2, 3, 4, 5, 6, 7 and the function call reverse(A, 2, 6) is made, then on return, the array A will contain 1, 2, 7, 6, 5, 4, 3 (i.e., A[0] and A[1] remain unchanged, and A[2] to A[6] get reversed). What will come in the missing lines (X, Y) in the function so that it reverses the part of the array A between leftindex and rightIndex? void reverse(int A[], int leftIndex, int rightIndex) { int temp; if ( X ) { temp = A[left + Index]; A[leftIndex] = A[rightIndex]; A[rightIndex] = temp; reverse (Y);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
