void reverse(int arr[],int low,int high)
{
while(low<=high)
{
int temp=arr[low];
arr[low]=arr[high];
arr[high]=temp;
low++;
high--;
}
}
//Function to rotate an array by d elements in counter-clockwise direction.
void rotateArr(int arr[], int d, int n)
{
if(d>n)
{
d=d%n;
}
reverse(arr,0,d-1);
reverse(arr,d,n-1);
reverse(arr,0,n-1);
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter