MCPcopy Create free account
hub / github.com/geekcomputers/Python / merge

Function merge

Sorting Algorithms/Iterative Merge Sort.py:40–68  ·  view source on GitHub ↗
(a, l, m, r)

Source from the content-addressed store, hash-verified

38
39# Merge Function
40def merge(a, l, m, r):
41 n1 = m - l + 1
42 n2 = r - m
43 L = [0] * n1
44 R = [0] * n2
45 for i in range(0, n1):
46 L[i] = a[l + i]
47 for i in range(0, n2):
48 R[i] = a[m + i + 1]
49
50 i, j, k = 0, 0, l
51 while i < n1 and j < n2:
52 if L[i] > R[j]:
53 a[k] = R[j]
54 j += 1
55 else:
56 a[k] = L[i]
57 i += 1
58 k += 1
59
60 while i < n1:
61 a[k] = L[i]
62 i += 1
63 k += 1
64
65 while j < n2:
66 a[k] = R[j]
67 j += 1
68 k += 1
69
70
71# Driver code

Callers 1

mergeSortFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected