Explore
ProGrad Programs
Placement Prep
TCS Codevita
Live Placement Training
Webinars
About Us

Edit
Reply




Edit

Array Rotation | Program for Left and Right Rotation of an Array

Published on 06 Mar 2020

Array Rotation simply means shifting the array elements to the left or right of the array by specified positions. An array can be rotated to the left(clockwise) or to the right (anti-clockwise) to the given number of positions. Now let us look at a program for left rotation of an array and right rotation of an array.

 

Left Rotation of Array 


Left rotation of an array means shifting of the elements in an array towards the left as shown in the below image. Left rotation means rotating the elements of the array in a clockwise direction to the specified number of positions.

Left array rotation



C++
Java
Python 3

Output
Array Elements before rotating:
1 2 3 4 5 6 7

Array Elements after rotating:
2 3 4 5 6 7 1

 

 

Right Rotation of Array 


Right rotation of an array means rotating the array elements towards the right of the array as shown in the below image. Right rotation means rotating the elements of the array in the anti-clockwise direction to the specified number of positions.

Right array rotation


C++
Java
Python 3

Output
Array Elements before rotating:
1 2 3 4 5 6 7 8 9 10

Array Elements after rotating:
9 10 1 2 3 4 5 6 7 8

If you have any feedback about this article and want to improve this, please write to enquiry@faceprep.in
Explore 'c plus plus'
Articles Practice Exercises