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]
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]
cyclically rotate an array by one
# Python3 code for program to
# cyclically rotate an array by one
# Method for rotation
def rotate(arr, n):
x = arr[n - 1]
for i in range(n - 1, 0, -1):
arr[i] = arr[i - 1];
arr[0] = x;
# Driver function
arr= [1, 2, 3, 4, 5]
n = len(arr)
print ("Given array is")
for i in range(0, n):
print (arr[i], end = ' ')
rotate(arr, n)
print ("nRotated array is")
for i in range(0, n):
print (arr[i], end = ' ')
# This article is contributed
# by saloni1297
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us