#! /usr/bin/env python
#coding=utf-8
def Merge(arr, p, q, r):
n1=q-p+1
n2=r-q
left=[0]*(n1+1)
right=[0]*(n2+1)
for i in range(0, n1):
left[i]=arr[p+i]
for j in range(0, n2):
right[j]=arr[q+j+1]
i=j=0
left[n1]=65535
right[n2]=65535
for k in range(p, r+1):
if left[i] <= right[j]:
arr[k]=left[i]
i=i+1
else:
arr[k]=right[j]
j=j+1
def MergeSort(arr, p, r):
if p<r:
q=(p+r)/2
MergeSort(arr, p, q)
MergeSort(arr, q+1, r)
Merge(arr, p, q, r)
if __name__ == '__main__':
arr = [2,4,7,9,1,5,11,566,6,32,11,1]
MergeSort(arr, 0, len(arr)-1)
print arr
#coding=utf-8
def Merge(arr, p, q, r):
n1=q-p+1
n2=r-q
left=[0]*(n1+1)
right=[0]*(n2+1)
for i in range(0, n1):
left[i]=arr[p+i]
for j in range(0, n2):
right[j]=arr[q+j+1]
i=j=0
left[n1]=65535
right[n2]=65535
for k in range(p, r+1):
if left[i] <= right[j]:
arr[k]=left[i]
i=i+1
else:
arr[k]=right[j]
j=j+1
def MergeSort(arr, p, r):
if p<r:
q=(p+r)/2
MergeSort(arr, p, q)
MergeSort(arr, q+1, r)
Merge(arr, p, q, r)
if __name__ == '__main__':
arr = [2,4,7,9,1,5,11,566,6,32,11,1]
MergeSort(arr, 0, len(arr)-1)
print arr