Merge sort code in Python using recursion -
Below is a merge sort written in Python, it is throwing error "runtime error: exceeded maximum recurring depth" error is. Please tell me if I remember the reasoning to end recursive. List for ([1] lane (list1) + lane (list2)
list = [] list1 = [] list2 = [] def merge (list, list1, list2) ): I = 1 Jammu = 1 if list1 [i]> gt; [2]: List [k] = list2 [j] j = + 1 k = + 1 other: list [k] = list2 [i] i = + 1 k = + 1 def partition (list, list 1, list 2 ): If the lane (list) <1> list1 = list [: lane (list) / list (list, list1, list2) list = [15, 8, 59, 69, 45, 23] sort (list)
Try this program:
def sort (AList): aList = _mergesort (aList, 0, len (aList) - 1) aList def _mergesort (alist, first, last)): middle = (first + last) / 2 if first & lt; Last: _mergesort (aList, first, middle) _mergesort (aList, middle + 1, last) a, f, l = 0, first, middle + 1 tmp = [none] * (last - first + 1) Lt; = Middle & L & lt; = Final: If ALIIS [F] & lt; ALIIT [L]: TMP [A] = ALIIT [F] F + = 1 suffix: TMP [A] = ALITIS [L] L + = 1 A + 1 if F & LT; = Mid: TMP [A:] = ALIIT [F: Middle + 1] If L & T = Last: TMP [A:] = ALIIT [L: last + 1] A = 0 while previously & lt; = Last: ALIF [first] = TMP [A] first + = 1a + = 1 return aList aList = [15,8,59,69,45,23] Print sort (alast)
Comments
Post a Comment