thanks
Write the recursive function from the above recursive algorithm as follows: void reverse (int intArray[], int low, int high) ( // base case // general case //swap element at low and element at high int tempEle intArray[low]; intArray [low] = intArray [high]; intArray [high] = tempEle; reverse (intArray, low + 1, high - 1); } if (low >= high) return; Step 2 of 4 A else
The complete program is as follows: The following program demonstrates the functionality of the recursive function reverse(): #include <iostream> using namespace std; void reverse (int { if (low > high) return; else { } } int main() Step 3 of 4 A intArray[], int low, int high) // base case // general case //swap element at low and element at high int tempEle = intArray [low]; elements: for { intArray [low] = intArray [high]; intArray [high] = tempEle; reverse (intArray, low + 1, high - 1); int LENGTH= 10; int intArray[] = {1,2,3,4,5,6,7,8,9,10 1: //print the initial array elements cout << "Initial intArray elements: " << endl; for (int i = 0; i < LENGTH; i++) { cout << intArray << " "; } cout << endl; //reverse the elements between indices 2 and 4 reverse (intArray, 2, 4); //print the array elements after reversing elements between indices 2 and 4 cout << "After reversing elements between 2 and 4, intArray " << endl; (int i = 0; i < LENGTH; i++) cout << intArray << " "; } return 0;
thanks
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am