We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5c0973e commit 63b706eCopy full SHA for 63b706e
pygorithm/sorting/merge_sort.py
@@ -48,15 +48,25 @@ def sort(_list):
48
b = sort(_list[middle:])
49
return merge(a, b)
50
51
-def sort_iter(_list):
+from itertools import zip_longest
52
+def sorti(_list):
53
"""
54
Function to sort an array
55
using merge sort algorithm, iteratively
56
57
:param _list: list of values to sort
58
:return: sorted
59
- pass
60
+ # breakdown every element into its own list
61
+ series = [[i] for i in _list]
62
+ while len(series) > 1:
63
+ # iterator to handle two at a time in the zip_longest below
64
+ isl = iter(series)
65
+ series = [
66
+ merge(a, b) if b else a
67
+ for a, b in zip_longest(isl, isl)
68
+ ]
69
+ return series[0]
70
71
# TODO: Are these necessary?
72
def time_complexities():
0 commit comments