In: Computer Science
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array.
Please complete this in C++
void findIndex(int *arr, int size, int a, int b) {
int i;
int max = arr[0];
int min = arr[0];
for (i = 1; i < size; i++) {
if (arr[i] < min) min = arr[i];
if (arr[i] > max) max = arr[i];
}
arr[a] = min;
arr[b] = max;
}