Question

*****************************CODE SHOULD BE WRITTEN IN C++************************ Write a function to reverse an array of integers starting...

*****************************CODE SHOULD BE WRITTEN IN C++************************

Write a function to reverse an array of integers starting from a given start index and a given end index. Note, the end index is inclusive. Add code to the given function below.

*********************FUNCTION TO BE USED***********************************************

#include "problem1.h"

void reverseArray(int arr[], int start, int end)

{

//written code

}

************************************EXAMPLE************************************************
int[] a = {1,2,3};
reverseArray(a, 0, 2);
//The content of a should be {3,2,1}.

int[] a = {1,2,3};
reverseArray(a, 0, 1);
//The content of a should be {2,1,3}.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
void reverseArray(int arr[], int start, int end)
{
    int left = start, right = end, temp;
    while (left < right) {
        temp = arr[left];
        arr[left] = arr[right];
        arr[right] = temp;
        left++;
        right--;
    }
}
Add a comment
Know the answer?
Add Answer to:
*****************************CODE SHOULD BE WRITTEN IN C++************************ Write a function to reverse an array of integers starting...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT