Golang 版本
func mergeSort(q []int, l int, r int) {
if l >= r {
return
}
mid := (r-l)/2+l
mergeSort(q, l, mid)
mergeSort(q, mid+1, r)
i, j, k := l, mid+1, 0
p := make([]int, r-l+1)
for i <= mid && j <= r {
if q[i] <= q[j] {
p[k] = q[i]
i++
} else {
p[k] = q[j]
j++
}
k++
}
for i <= mid {
p[k] = q[i]
i++
k++
}
for j <= r {
p[k] = q[j]
j++
k++
}
for i, j := l, 0; i <= r; {
q[i] = p[j]
i++
j++
}
}