Using C Write a recursive function that reverses an array vo

Using C++:
Write a recursive function that reverses an array: void reverse Array (Array Type a, int first, int last);/* reverse the contents of a[first], ..., a[last] */

Solution

void reverseArray(int array[], int first, int last){
   int temp;
   if(first < last){
       temp=array[first]; // assaign array first element to temp
       array[first]=array[last];// now last element to first element
       array[last]=temp;// first element to last element(i.e temp = first)
       // recursively calling reverseArray fucntion
       reverseArray(array, first+1,last-1);
   }

}

Using C++: Write a recursive function that reverses an array: void reverse Array (Array Type a, int first, int last);/* reverse the contents of a[first], ..., a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site