Skip to content

Commit

Permalink
Merge pull request #89 from DragoVeizen/main
Browse files Browse the repository at this point in the history
Python program to merge two sorted arrays -> Issue #38
  • Loading branch information
ademclk authored Oct 23, 2022
2 parents 1682fcd + f77ddee commit 22890da
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions challenges/Python/MergeSortedArrays/Mergesortarrays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Python program to merge two sorted arrays
def mergeArrays(arr1, arr2, x, y, arr3):
i = 0
j = 0
k = 0

while(i < x):
arr3[k] = arr1[i]
k += 1
i += 1

while(j < y):
arr3[k] = arr2[j]
k += 1
j += 1

arr3.sort()

if __name__ == '__main__':
arr1 = [1, 3, 5, 7]
x = len(arr1)

arr2 = [2, 4, 6, 8]
y = len(arr2)

arr3 = [0 for i in range(x+y)]
mergeArrays(arr1, arr2, x,y, arr3)

print("Array after merging")
for i in range(x + y):
print(arr3[i], end=" ")

0 comments on commit 22890da

Please sign in to comment.