Skip to content

Commit 711ecc4

Browse files
committed
Array Programs: Reversing array elements
1 parent 45f1e39 commit 711ecc4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Arrays/P01_ReversingArray.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Author: OMKAR PATHAK
2+
3+
import Arrays
4+
5+
def reversingAnArray(start, end, myArray):
6+
while(start < end):
7+
myArray[start], myArray[end - 1] = myArray[end - 1], myArray[start]
8+
start += 1
9+
end -= 1
10+
11+
if __name__ == '__main__':
12+
myArray = Arrays.Array(10)
13+
myArray.insert(2, 2)
14+
myArray.insert(1, 3)
15+
myArray.insert(3, 1)
16+
print('Array before Reversing:',myArray)
17+
reversingAnArray(0, len(myArray), myArray)
18+
print('Array after Reversing:',myArray)

0 commit comments

Comments
 (0)