forked from OmkarPathak/Data-Structures-using-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP02_ArrayRotation.py
More file actions
24 lines (18 loc) · 615 Bytes
/
P02_ArrayRotation.py
File metadata and controls
24 lines (18 loc) · 615 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Author: OMKAR PATHAk
from Arrays import Array
def rotation(rotateBy, myArray):
for i in range(0, rotateBy):
rotateOne(myArray)
return myArray
def rotateOne(myArray):
for i in range(len(myArray) - 1):
myArray[i], myArray[i + 1] = myArray[i + 1], myArray[i]
if __name__ == '__main__':
myArray = Array(10)
for i in range(len(myArray)):
myArray.insert(i, i)
print('Before Rotation:',myArray)
print('After Rotation:',rotation(3, myArray))
# OUTPUT:
# Before Rotation: 0 1 2 3 4 5 6 7 8 9
# After Rotation: 3 4 5 6 7 8 9 0 1 2