Write the definition of a function Reverse(int Arr[], int N) in C++, which should reverse the entire content of the array Arr having N elements, without using any other array.
Example: if the array Arr contains
13 | 10 | 15 | 20 | 5 |
Then the array should become
5 | 20 | 15 | 10 | 13 |
NOTE:
- The function should only rearrange the content of the array.
- The function should not copy the reversed content in another array.
- The function should not display the content of the array.
void printarray(int arr[], int count)
{
for(int i = 0; i < count; ++i)
cout<<arr[i]<<' ';
cout<<'\n';
}
void reverse(int arr[], int count)
{
int temp;
for (int i = 0; i < count/2; ++i)
{
temp = arr[i];
arr[i] = arr[count-i-1];
arr[count-i-1] = temp;
}
}
int main ()
{
clrscr();
const int SIZE = 10;
int arr [SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
cout<<'Input Array\n';
printarray(arr, SIZE);
reverse(arr, SIZE);
cout<<'Reverse Array\n';
printarray(arr, SIZE);
getch();
}