Skip to content

Commit 1893306

Browse files
Merge pull request #103 from adenashameem/master
Added the program: Rotate an array to the left by 3 positions
2 parents 37ab80b + 82da33b commit 1893306

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Array/Rotate_Left.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# coding: utf-8
3+
4+
# In[ ]:
5+
6+
7+
8+
9+
arr = list();
10+
n=input("Enter the number of elements you want in the array: ")
11+
12+
print("Enter the array elements one by one:")
13+
for i in range(int(n)):
14+
ele=input()
15+
arr.append(int(ele))
16+
17+
#Display the original array
18+
print("Array before rotation is: ")
19+
for i in range(0, len(arr)):
20+
print(arr[i])
21+
22+
#Rotate the given array by 3 times towards left
23+
for i in range(0, 3):
24+
#Stores the first element of the array
25+
first = arr[0]
26+
27+
for j in range(0, len(arr)-1):
28+
#Shift element of array by one
29+
arr[j] = arr[j+1]
30+
31+
#First element of array will be added to the end
32+
arr[len(arr)-1] = first
33+
34+
print()
35+
36+
#Display the array after 3 left rotations
37+
print("Array after 3 left rotations is: ");
38+
for i in range(0, len(arr)):
39+
print(arr[i])
40+

0 commit comments

Comments
 (0)