Array manipulationWrite the following array functions. You can assume that these are integer arrays. You implementation should not use [ ] operators. Instead use pointers to access array elements. Suppose, arr[] = {1, 4, 6, 5, 2, 7, 10}.A. Search for a given value in the array and return the index of the location. Return - 1 if not found in the array. void search(int arr[], int n, int val); Using the above array arr, search(arr, 7, 6) should return 2, and search(arr, 7, 8) should return -1.B. Reverse the contents of the array. void reverse(int arr[], int n); Using the above array arr, reverse(arr, 7) should return result in arr contents rearranged as follows: arr = {10, 7, 2, 5, 6, 4, 1}.C. Rearrange the array such that all the odd elements in the array are in the beginning of the array. void oddFirst(int arr[], int n); Using the above array arr, oddFirst(arr, 7) should return result in arr contents rearranged as follows: arr = {1, 5, 7, 4, 6, 2, 10}.

Respuesta :

Answer:

C++.

Explanation:

int arr[] = {1, 4, 6, 5, 2, 7, 10};

///////////////////////////////////////////////////////////////////////////////

// Methods

int searchValue(int arr[], int n, int value) {

   int* pointerArray = arr;

   for (int i = 0; i < n; i++) {

       if (*(pointerArray + i) == value) {

           delete[] pointerArray;

           return i;

       }

   }

   delete[] pointerArray;

   return -1

}

void reverse(int arr[], int n) {

   int tempArr[n] = arr;

   int* pointerArray = arr

   int* pointerArray2 = tempArr;

   for (int i = 0; i < n; i++) {

       *(pointerArray2 + i) = *(pointerArray + ((n-1) - i));

   }

   arr = tempArr;

   delete[] pointerArray, pointerArray2;

}

void oddFirst(int arr[], int n) {

   int* pointerArray = arr;

   int count = 0;

   for (int i = 0; i < n; i++) {

       if ((*(pointerArray + i) % 2) != 0) {

           int temp = *(pointerArray + i);

           *(pointerArray + i) = *(pointerArray + count);

           *(pointerArray + count) = temp;

           count++;

       }

   }

   delete[] pointerArray;

}

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE