Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

tri fusion python code

def m(left, right):
    if not len(left) or not len(right):
        return left or right
 
    result = []
    i, j = 0, 0
    while (len(result) < len(left) + len(right)):
        if left[i] < right[j]:
            result.append(left[i])
            i+= 1
        else:
            result.append(right[j])
            j+= 1
        if i == len(left) or j == len(right):
            result.extend(left[i:] or right[j:])
            break
 
    return result
 
def msort(list):
    if len(list) < 2:
        return list
 
    middle = int(len(list)/2)
    left = msort(list[:middle])
    right = msort(list[middle:])
 
    return m(left, right)
     
lst = [5, 9, 3, 7, 15, 6]
print("Given List:")
print(lst);
print("
")
print("Sorted List:")
print(msort(lst))
Source by www.delftstack.com #
 
PREVIOUS NEXT
Tagged: #tri #fusion #python #code
ADD COMMENT
Topic
Name
4+5 =