Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

//RIGHT ROTATION BY REVERSE ALGORITHM

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int reversearray(int arr[],int start,int end){


int temp;
while(start<end){
temp=arr[start];
arr[start]=arr[end];
arr[end]=temp;
start++;
end--;
}
}

int rightrotate(int arr[],int n,int d){


reversearray(arr,0,n-1);
reversearray(arr,0,d-1);
reversearray(arr,d,n-1);
}

int main() {
int t;
cin>>t;
while(t--){
int n,k;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
cin>>k;
rightrotate(arr,n,k);
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
return 0;
}

You might also like