Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Merge Two Sorted List.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Merge two Sorted List
def merge(arr1, arr2, n, m):
i = 0
j = 0
temp = [0]*(n+m)
k = 0
while i < n and j < m:
if arr1[i] < arr2[j]:
temp[k] = arr1[i]
i += 1
else:
temp[k] = arr2[j]
j += 1
k += 1

while i < n:
temp[k] = arr1[i]
i += 1
k += 1

while j < m:
temp[k] = arr2[j]
j += 1
k += 1
return temp


arr1 = [1, 3, 5, 7]
arr2 = [0, 2, 6, 8, 9]
print(merge(arr1, arr2, len(arr1), len(arr2)))
19 changes: 19 additions & 0 deletions Rearrange Positive and Negative Values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Rearrange Positive and Negative Values
def moveAll(arr, low, high):
while low <= high:
if arr[low] > 0 and arr[high] < 0:
arr[low], arr[high] = arr[high], arr[low]
low += 1
high -= 1
elif arr[low] > 0 and arr[high] > 0:
high -= 1
elif arr[low] < 0 and arr[high] < 0:
low += 1
else:
low += 1
high -= 1
print(arr)


arr = [-12, 11, -13, -5, 6, -7, 5, -3, 11]
moveAll(arr, 0, len(arr)-1)