mark
def Merge(A,p,q,r):
# print (A,p,q,r)
n1 = q-p+1
n2 = q-p
# print ("A",A,type(A),p,q)
L=A[p:q+1]
# print ("L",L)
R=A[q+1:r+1]
# print ("R",R)
L.append(100000)
R.append(100000)
i = 0
j = 0
k = p
while (k<=r):
# print ("LR",L[i] ,R[j])
if (L[i] == R[j]) and (L[i] == 100000):
break
if L[i] <= R[j]:
A[k] = L[i]
i = i+1
else:
A[k] = R[j]
j = j+1
# print ("one A",k,A)
k=k+1
def MergeSort(A,p,r):
if p<r:
q=(p+r)/2
print ("M:A",A,"p",p,"r",r)
MergeSort(A,p,q)
MergeSort(A,q+1,r)
Merge(A,p,q,r)
def main():
A=[8,4,5,7,1,2,3,6]
print (A)
MergeSort(A,0,7)
print ("result A",A)
if __name__ == '__main__':
main()
running result: