"""
Created on Thu Oct 09 17:32:31 2014
@author: Zharma
Describe: input:A 要排序的序列
p 要排序的起始元素下标
r 要排序的最后一个元素的下标
排序内容可以为A的全部序列或者部分序列
"""
def merge(A, p, q, r):
L = A[p: q + 1]
R = A[q + 1: r + 1]
print R
L.append('None')
R.append('None')
i = 0
j = 0
for e in range(p, r + 1):
if L[i] <= R[j]:
A[e] = L[i]
i += 1
else:
A[e] = R[j]
j += 1
def merge_sort(A, p, r):
if p < r:
q = (p + r)/2
merge_sort(A, p, q)
merge_sort(A, q + 1, r)
merge(A, p, q, r)
偶尔有时间,来一发算法,自娱自乐