Complete the code to reverse the array using a simple loop.
for (int i = 0; i < n / 2; i++) { int temp = arr[i]; arr[i] = arr[[1]]; arr[[1]] = temp; }
The index to swap with is the element from the end, which is n - i - 1.
Complete the code to reverse the array using the std::reverse function.
#include <algorithm> std::reverse(arr, arr + [1]);
The std::reverse function reverses elements from the start pointer to one past the last element, so use arr + n.
Fix the error in the recursive array reversal function by completing the base case condition.
void reverseArray(int arr[], int start, int end) {
if ([1]) {
return;
}
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
reverseArray(arr, start + 1, end - 1);
}The recursion should stop when the start index is greater than or equal to the end index.
Fill both blanks to create a map of array elements to their reversed indices.
std::map<int, int> reversedIndices; for (int i = 0; i < n; i++) { reversedIndices[arr[i]] = [1] - [2]; }
The reversed index for element at i is n - 1 - i.
Fill all three blanks to create a reversed copy of the array using a for loop.
int reversed[n]; for (int [1] = 0; [1] < n; [1]++) { reversed[[2]] = arr[[3]]; }
Use i as loop variable, assign reversed[n - i - 1] from arr[i] to reverse the array.
