logo CodeStepByStep logo

reverseFirstK

Language/Type: C++ vector traversals STL
Related Links:

Write a function named reverseFirstK that accepts a reference to a vector of integers and an index k as parameters and modifies the first k elements of the vector to be in reverse order. For example, if the vector a stores {10, -2, 33, 55, 9, 17, 6}, the call of reverseFirstK(a, 5) should reverse the first 5 elements, modifying it to store {9, 55, 33, -2, 10, 17, 6}. If the value of k is 1, 0, negative, or greater than the length of the vector, do not modify the vector.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.