uppose that intArray is an array of integers, and length specifies the number of elements in intArray. Also, suppose that low and high are two integers such that 0 <= low < length, 0 <= high < length, and low < high. That is, low and high are two indices in intArray. Write a recursive definition that reverses the elements in intArray between low and high.
c++
Suppose that intArray is an array of integers, and length specifies the number of elements in intArray. Also, suppose that low and high are two integers such that 0 <= low < length, 0 <= high < length, and low < high. That is, low and high are two indices in intArray. Write a recursive definition that reverses the elements in intArray between low and high.
Your base case for recursion should be when low becomes greater than high
Otherwise, just swap the current low and high value and send to recursion with low increased and high decreased
void reverse(int intArray, int len, int low, int high)
{
if(low>high)
return;
int temp=intArray[low];
intArray[low]=intArray[high];
intArray[high]=temp;
reverse(intArray, len, low+1, high-1);
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images