void rightRotate(int arr[], int d, int n){
while (d > n) {
d = d - n;
}
int temp[] = new int[n - d];
for (int i = 0; i < n - d; i++)
temp[i] = arr[i];
for (int i = n - d; i < n; i++) {
arr[i - n + d] = arr[i];
}
for (int i = 0; i < n - d; i++) {
arr[i + d] = temp[i];
}
}
Right Rotate Array
This code creates an array arr of size n, initializes its elements to 0, and then rotates the array right around its current position by d positions. It then adds the values of the elements in the rotated array to the values of the elements in the original array arr, starting at the original position.
0 Comments
Add Comment
Log in to add a comment