
Computer Science Application
Arrays, Arraylists and 2D Arrays Solutions
Requirements:
- no global variable is allowed.
- there is no printing or reading in the function (e.g. there is no usage of cin and
cout).
Printing and reading are done outside these functions.
- there is ng multiple return statements in a function. In another word, there should
be only at most one return statement in each function.
R. Write a function named "rotate" that accepts an array of integers and its size and a
boolean "isLeft" flag to indicate the direction of left or right.
If the flag is true, it will rotate all the values to the left and moving the value of the
first element in the array to last.
If the flag is false, it will rotate all the values to the rigth and moving the last element
in the array to the first.
For example, for the array of {10, 20, 30, 40}
if "isLeft" flag is true, it will become {20, 30, 40, 10}
if "isLeft" flag is false, it will become {40, 10, 20, 30).