Tracing an Array Rotation Method
Given the following method call, rightRotate(new int[]{1, 2, 3, 4, 5}, 3);, what will be the state of the array after the function execution?
Consider the following method:
public static void rightRotate(int[] data, int shift) {
int len = data.length;
shift = shift % len;
for (int start = 0; start < 1; start++) {
int current = start;
int prevVal = data[current];
boolean first = true;
while (first || current != start) {
first = false;
int next = (current + shift) % len;
int temp = data[next];
data[next] = prevVal;
prevVal = temp;
current = next;
}
}
}
Given the following method call, rightRotate(new int[]{1, 2, 3, 4, 5}, 3);, what will be the state of the array after the function execution?
A
4, 5, 3, 2, 1
B
3, 4, 5, 1, 2
C
5, 1, 2, 3, 4
D
5, 4, 3, 2, 1
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE