Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

cyclically rotate an array by one

def rotate( arr, n):
    a[0],a[1:]=a[-1],a[:n-1]
    
#Driver Code    
a=[-1,2,3,7,5]
rotate(a,len(a))
print(a)
#Output: [5, -1, 2, 3, 7]
 
PREVIOUS NEXT
Tagged: #cyclically #rotate #array
ADD COMMENT
Topic
Name
1+9 =