View difference between Paste ID: 62KJ47ta and a5nUdR1k
SHOW: | | - or go back to the newest paste.
1
# algorithm http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Sorting/mergeSort.htm
2
def msort2(x):
3
    if len(x) < 2:
4
        return x
5
    result = []          # moved!
6
    mid = int(len(x)/2)
7
    y = msort2(x[:mid])
8
    z = msort2(x[mid:])
9
    while (len(y) > 0) and (len(z) > 0):
10
            if y[0] > z[0]:
11
                result.append(z[0])
12
                z.pop(0)
13
            else:
14
                result.append(y[0])
15
                y.pop(0)
16
    result += y
17
    result += z
18
    return result