admin@onlinelearningcenter.in (+91) 7 999 01 02 03

rotate an Array

suraz Ghimire
5 Posts

Given an Array arr, factor f, direction d, rotate an array with the factor f in reverse or Forward direction.

 

Eg: arr={1,2,3,4,5,6} f=2,direction=-1 (Move to Left)

Output: {3,4,5,6,1,2}

Explanation: The array would shift to the Left side as the direction is -ve

 

Eg: arr={1,2,3,4,5,6} f=2,direction=3 (Move to Right)

Output: {3,4,5,6,1,2}

Explanation: The array would shift to the Right side as the direction is +ve. The direction value does not matter

 

Eg: arr={1,2,3,4,5,6} f=2,direction=0 (No movement)

Output: {1,2,3,4,5,6}

Explanation: The array would not shift anywhere as direction is neutral

 

Published By : suraz Ghimire
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Comments

Jquery Comments Plugin