Skip to content

Commit 2731ebc

Browse files
committed
Array Programs: Reversing Array elements
1 parent 711ecc4 commit 2731ebc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Arrays/P02_ArrayRotation.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Author: OMKAR PATHAk
2+
3+
from Arrays import Array
4+
5+
def rotation(rotateBy, myArray):
6+
for i in range(0, rotateBy):
7+
rotateOne(myArray)
8+
return myArray
9+
10+
def rotateOne(myArray):
11+
for i in range(len(myArray) - 1):
12+
myArray[i], myArray[i + 1] = myArray[i + 1], myArray[i]
13+
14+
15+
if __name__ == '__main__':
16+
myArray = Array(10)
17+
for i in range(len(myArray)):
18+
myArray.insert(i, i)
19+
print('Before Rotation:',myArray)
20+
print('After Rotation:',rotation(3, myArray))
21+
22+
# OUTPUT:
23+
# Before Rotation: 0 1 2 3 4 5 6 7 8 9
24+
# After Rotation: 3 4 5 6 7 8 9 0 1 2

0 commit comments

Comments
 (0)