清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
def merge_sort(a, b) if a.length > 1 temArr = split_array(a) a = merge_sort(temArr[0], temArr[1]) if b.length > 1 temArr = split_array(b) b = merge_sort(temArr[0], temArr[1]) end end final = [] until a.empty? or b.empty? final << (a.first < b.first ? a.shift : b.shift) end final + a + b end def split_array a tem = [] tem << a.shift((a.length + 1)/2) tem << a end a=*0..20 a.reverse! a.shuffle! p a s = split_array a p merge_sort s[0], s[1]